Jump Game II
Part of Practice: Reach & Reset
You start at index 0 of an integer array nums, where nums[i] is the maximum jump length from index i. Unlike Jump Game I, the last index is guaranteed to be reachable — your job is to reach it using the fewest jumps, and return that count.
Constraints that matter: up to 10,000 elements, so an O(n²) "try every jump from every index" approach passes only barely; the expected answer is a single linear pass.
Examples
- Input:
- nums = [2, 3, 1, 1, 4]
- Output:
- 2
Jump from index 0 to index 1 (1 step), then from index 1 straight to the last index (3 steps). Two jumps total.
- Input:
- nums = [2, 3, 0, 1, 4]
- Output:
- 2
- Input:
- nums = [0]
- Output:
- 0
You are already standing on the last index.
Hints
One at a time — struggle first, peek second.
Your thinking space — verify on LeetCode, then mark it.