1340. Jump Game V
Last updated
Last updated
https://leetcode.com/problems/jump-game-v
Given an array of integers arr
and an integer d
. In one step you can jump from index i
to index:
i + x
where: i + x < arr.length
and 0 < x <= d
.
i - x
where: i - x >= 0
and 0 < 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 can not jump outside of the array at any time.
Example 1:
Example 2:
Example 3:
Example 4:
Example 5:
Constraints:
1 <= arr.length <= 1000
1 <= arr[i] <= 10^5
1 <= d <= arr.length