Jump Game II

Find the minimum number of jumps to reach the last index.

Pattern

BFS-like Greedy

This problem follows the BFS-like Greedy pattern, commonly found in the Greedy category. Recognizing this pattern is key to solving it efficiently in an interview setting.

Approach

How to Solve It

Track current window end and farthest reach. When you hit window end, jump.

Key Insight

Think of it as BFS on a number line — each 'level' is a jump, and curEnd marks where the current level ends.

Step-by-step

  1. 1Track the end of the current jump range and the farthest reachable
  2. 2When you reach the end of the current range, you must jump
  3. 3Update the range end to the farthest reachable, increment jumps

Pseudocode

jumps = 0
curEnd = 0
farthest = 0
for i in range(len(nums) - 1):
    farthest = max(farthest, i + nums[i])
    if i == curEnd:
        jumps += 1
        curEnd = farthest
return jumps
Complexity Analysis

Time Complexity

O(n)

Space Complexity

O(1)
More Greedy Problems

Master this pattern with YeetCode

Practice Jump Game II and similar Greedy problems with flashcards. Build pattern recognition through active recall.

Practice this problem