Minimum Jumps to Reach the End
Problem
Given an array nums[] where nums[i] is the maximum forward jump length from index i, return the minimum number of jumps needed to reach the last index. You are guaranteed to be able to reach it.
Input / Output
- Input: an integer array
nums[]. - Output: the minimum number of jumps from index 0 to index
n-1.
Constraints
1 <= nums.length <= 10^4,0 <= nums[i] <= 1000.- The last index is always reachable.
- Input is large enough that materialising the implied graph and traversing every edge is too slow — the intended solution is linear.
Example
nums = [2,3,1,1,4]→2. Jump 0→1, then 1→4.- Tricky case:
nums = [2,3,0,1,4]→2. The naive "jump as far as possible" sends you 0→2, a near dead end; the correct move is 0→1, the position within reach that opens up the furthest subsequent reach.
asked …