Jump Game II
Module 22 · Greedy
Problem
Same setup as Jump Game: integer array nums, start at index 0,
nums[i] is the maximum jump length from i. This time you're
guaranteed the last index is reachable, and you must return the
minimum number of jumps to get there.
Examples
Example 1
nums = [2,3,1,1,4]Output2Explanation. 0 to 1, then to 4
Example 2
nums = [2,3,0,1,4]Output2First case: jump 0 → 1 → 4 (two jumps). 0 → 2 → ? also works but never fewer.
Second case: jump 0 → 1 → 4.
Constraints
1 ≤ n ≤ 10⁴ · 0 ≤ nums[i] ≤ 1000 · last index always reachable.
Attempt it first
You already know from Jump Game that tracking max_reach captures
reachability. The new question is counting jumps — so the natural
first instinct is a shortest-path / BFS framing. Try to write it that
way before revealing the hint, then look for how to get the same answer
without an explicit queue.