#55
Medium
Greedy

Jump Game

Decide whether you can reach the last index.

ArrayGreedy

Pattern fit

A single farthest-reachable boundary is enough, which makes the problem a perfect example of a greedy invariant instead of DP.

Key observation

As long as your index stays within the current farthest reach, you can extend that reach using nums[i].

Target complexity

O(n) / O(1)

How to break down the solution cleanly

1

A single farthest-reachable boundary is enough, which makes the problem a perfect example of a greedy invariant instead of DP.

2

As long as your index stays within the current farthest reach, you can extend that reach using nums[i].

3

Identify the local choice that seems to preserve the most future flexibility.

4

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

warning

Stopping after one bad zero without checking whether it was already bypassed.

warning

Confusing minimum jumps with simple reachability.

Common follow-ups

Why is maintaining the farthest reach sufficient?

How does this relate to Jump Game II?

Continue with related problems

Build repeatable depth inside the Greedy cluster before moving on.

view_weekBack to the pattern page
LeetCode 55. Jump Game Guide | Interview AiBox