Odd Even Jump
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

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:
  • 1arr.length2×1041 \leq \text{arr.length} \leq 2 \times 10^4

  • 0arr[i]<1050 \leq \text{arr}[i] < 10^5

Input
arr ={"arr":[10,13,12,14,15]}

Array: [10, 13, 12, 14, 15], n=5

State
arr
[10, 13, 12, 14, 15]
n
5
Variables
No variables to display
DepthFunction Call
Stack empty
0/1