Jump Game V
Given an array of integers arr and an integer d, in one step you can jump from index i to another index:
i + x, wherei + x < arr.lengthand0 < x <= d.i - x, wherei - x >= 0and0 < x <= d.
In addition, you can only jump from index i to index j if arr[i] > arr[j] and arr[i] > arr[k] for all indices k between i and j (more formally, min(i, j) < k < max(i, j)).
You can choose any index of the array and start jumping. Return the maximum number of indices you can visit.
Notice that you cannot jump outside of the array at any time.
Example 1
Input
arr = [6,4,14,6,8,13,9,7,10,6,12], d = 2Output
4Starting at index 10, you can jump 10 --> 8 --> 6 --> 7, visiting 4 indices.
Example 2
Input
arr = [3,3,3,3,3], d = 3Output
1All values are equal, so you cannot jump from any index to another index.
Constraints
- 1 <= arr.length <= 1000
- 1 <= arr[i] <= 10^5
- 1 <= d <= arr.length