01 · Question
You are given two arrays of positive integers, p1 and p2, representing players in a racing game. The two arrays are sorted, non-empty, and have the same length, n. The i-th element of each array corresponds to where that player was on the track at the i-th second of the race. We know that:
- player 1 started ahead (
p1[0] > p2[0]), - player 2 overtook player 1 once, and
- player 2 remained ahead until the end (
p1[n - 1] < p2[n - 1]).
Assume the arrays have no duplicates, and that p1[i] != p2[i] for any index.
Return the index at which player 2 overtook player 1.
Example:
- Input:
p1 = [2, 4, 6, 8, 10], p2 = [1, 3, 5, 9, 11] - Output:
3