You are given an integer array arr. From some starting index, you can make a series of jumps. The first jump is odd, the second is even, and so on. From index i, during odd jumps you can jump to j where arr[j] is the smallest value >= arr[i] with j > i. During even jumps, jump to j where arr[j] is the largest value <= arr[i] with j > i. Return the number of good starting indices.
30:00
Java
Odd Even Jump
hard
Topics
Companies
You are given an integer array arr. From some starting index, you can make a series of jumps. The first jump is odd, the second is even, and so on. From index i, during odd jumps you can jump to j where arr[j] is the smallest value >= arr[i] with j > i. During even jumps, jump to j where arr[j] is the largest value <= arr[i] with j > i. Return the number of good starting indices.
Example 1:
Input: {"arr":[10,13,12,14,15]}
Output: 2
Constraints:
1≤arr.length≤2×104
0≤arr[i]<105
Input
arr ={"arr":[10,13,12,14,15]}
Array [10, 13, 12, 14, 15]. Work right to left: the last index is good from either parity.