Problem
Same board as Jump Game: from index i you may jump forward up to nums[i] places. This time the last index is always reachable. Return the fewest jumps needed to get there from index 0.
Example 1
- Input
- nums = [2, 3, 1, 1, 4]
- Output
- 2
- Why
- 0 → 1 → 4
Example 2
- Input
- nums = [2, 3, 0, 1, 4]
- Output
- 2
Example 3
- Input
- nums = [0]
- Output
- 0
- Why
- already there
Constraints
1 <= nums.length <= 10^40 <= nums[i] <= 1000The last index can always be reached.