Jump Game II
Problem
You are on the first cell of an integer array nums, where nums[i] is the maximum forward distance you can jump from cell i. It is guaranteed that the last cell is reachable. Return the minimum number of jumps needed to get from the first cell to the last.
numshas between 1 and 50,000 cells.- Each value is a non-negative integer no larger than 5,000.
- The last index is always reachable.
Examples
nums = [3, 1, 1, 4, 2, 1, 1]→2. Jump 3 to index 3, then 3 more to the end.nums = [1, 2, 1, 1, 1]→3. Index 0 to 1, then 2 to index 3, then 1 to the end; no cell has enough reach to save a jump.nums = [6]→0. Already at the end, no jumps needed.
Hints
- Think of each cell as a node with edges to the cells it can jump to. What algorithm gives the fewest edges in an unweighted graph?
- Every cell reachable in
jjumps forms a contiguous range. Why? What are the endpoints of the range forj + 1jumps? - Greedy sweep: track the end of the current jump's range and the farthest cell any position in that range can reach; when the sweep passes the current range's end, count a jump and adopt the farthest as the new end.
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.