783. Maximum Number of Matching Indices After Right Shifts
Given two integer arrays, nums1 and nums2, of the same length. An index i is considered matching if nums1[i] == nums2[i]. You can perform any number of right shifts on nums1. A right shift moves the element at index i to index (i + 1) % n for all indices. Return the maximum number of matching indices after performing any number of right shifts on nums1.
Example 1:
Input: nums1 = [4,2,6,4,2,6], nums2 = [2,6,4,2,6,4]
Output: 6
Explanation: If we right shift nums1 2 times, it becomes [2,6,4,2,6,4].
Every index matches, so the output is 6.
Example 2:
Input: nums1 = [3,5,1,6,2,4], nums2 = [6,2,3,1,5,7]
Output: 3
Explanation: If we right shift nums1 3 times, it becomes [6,2,4,3,5,1]. Indices 0, 1 and 4 matches so the output is 2.
Now Your Turn!
Pick the correct output for the given inputInput: nums1 = [7,9,3,8,6,2], nums2 = [9,3,8,6,2,7]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- nums1.length == nums2.length
- 1 <= nums1.length <= 3000
- 1 <= nums1[i], nums2[i] <= 109