Jump Game II
Find the minimum number of jumps to reach the last index.
Pattern fit
The greedy idea is to treat one jump as one BFS layer and keep the farthest boundary reachable inside the current layer.
Key observation
You only increment the jump count when the current layer ends, not every time you see a farther reach.
Target complexity
O(n) / O(1)
How to break down the solution cleanly
The greedy idea is to treat one jump as one BFS layer and keep the farthest boundary reachable inside the current layer.
You only increment the jump count when the current layer ends, not every time you see a farther reach.
Identify the local choice that seems to preserve the most future flexibility.
Sort or preprocess if that makes the choice testable.
Reference implementation
Python# Generic pattern template
items.sort(key=priority)
answer = 0
for item in items:
if can_take(item):
take(item)
answer = update(answer)
Common pitfalls
Incrementing jumps too early inside the same layer.
Not resetting the next-layer farthest boundary correctly.
Common follow-ups
Why is this greedy equivalent to BFS layering?
How would you detect an unreachable end position?
Continue with related problems
Build repeatable depth inside the Greedy cluster before moving on.