mediumGreedyArrayGreedy

Jump Game II

mediumTime: O(n)Space: O(1)

Signals to notice

minimum jumps to reach endeach position has a jump rangecount steps not reachability

Brute force first

BFS from index 0, each position enqueues all reachable positions. Processes every reachable index. It is a fair place to begin because it matches the surface of the question, yet it does not capture the deeper structure that makes the problem simpler.

The key insight

Greedy BFS: track the farthest reachable index and the end of the current 'level.' When you pass the current level's end, increment jumps and update the level boundary. Once you hold onto the right piece of information from moment to moment, the problem feels less like trial and error and more like following a shape that was there all along.

What must stay true

Each 'jump' covers all positions reachable from the current level. The farthest position reachable from this level becomes the boundary of the next level. You never need to revisit positions. If that remains true after every update, the rest of the reasoning has a stable place to stand.

Easy way to go wrong

Using actual BFS with a queue — the greedy approach achieves the same result without a queue by tracking the level boundary implicitly. When the code becomes mechanical before the idea is clear, small edge cases start breaking the whole story.

Greedy Pattern