Most Frequent Element in an Array
Problem Description
You are given two arrays. Assume that there are no duplicates in each of arrays.
Determine if two arrays are a rotated version of each other.
Example:
Input: A = [1, 2, 3, 4, 5, 6, 7], B = [4, 5, 6, 7, 1 ,2 ,3] Output: True
Input: A = [1, 2, 3, 4, 5, 6, 7], B = [1, 3, 5, 7, 9, 2, 4] Output: False
Solutions
One solution that comes up in my mind is to get an element from the first array, then see if that element can be found in the second array. If yes, we use that element as a start point in both arrays and then use two pointers, one for each array, to go through all elements to see if they are all match.
1 | bool isRotation(std::vector<int> a, std::vector<int> b){ |
1 | def is_rotation(A, B): |