n: ring and pattern. Position i is a match when ring[i] == pattern[i].
You may rotate ring to the right any number of times: one rotation moves every element from position i to position (i + 1) mod n, so the last element becomes the first. pattern stays as it is.
Return the largest number of matching positions you can reach by rotating.ring=[4, 8, 1, 6], pattern=[1, 6, 4, 8] → 4
After two shifts, ring becomes [1, 6, 4, 8] and matches pattern at all four positions.
ring=[2, 2, 5], pattern=[5, 3, 2] → 2
One shift gives [5, 2, 2], matching positions 0 and 2. Position 1 can never match, since ring has no 3.
ring=[1, 2, 3], pattern=[7, 8, 9] → 0
len(ring) = len(pattern)len(ring) ≤ 3000ring[i], pattern[i] ≤ 10⁹ring=[4, 8, 1, 6], pattern=[1, 6, 4, 8]
4
Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.