Maximum Number of Jumps to Reach the Last Index
You are given a 0-indexed array nums of n integers and an integer target.
You are initially positioned at index 0. In one step, you can jump from index i to any index j such that:
0 <= i < j < n-target <= nums[j] - nums[i] <= target
Return the maximum number of jumps you can make to reach index n - 1.
If there is no way to reach index n - 1, return -1.
Example 1
Input
nums = [1,3,6,4,1,2], target = 2Output
3The maximum jumping sequence is from index 0 to 1, then 1 to 3, then 3 to 5, for 3 jumps.
Example 2
Input
nums = [1,3,6,4,1,2], target = 3Output
5The maximum jumping sequence visits each next index from 0 through 5, for 5 jumps.
Constraints
- 2 <= nums.length == n <= 1000
- -10^9 <= nums[i] <= 10^9
- 0 <= target <= 2 * 10^9