Skip to content
GKgkml.dev
← Problem set
#55MediumGreedy & intervals

Jump Game

The tell: Reachability along a line, where a greedy running maximum suffices.

How you get there

  1. 1Track the furthest index reachable so far.
  2. 2If the current index ever exceeds that reach, the end is unreachable.
  3. 3One pass, no DP table needed.

Solution

Python
def can_jump(nums: list[int]) -> bool:
    reach = 0
    for i, jump in enumerate(nums):
        if i > reach:
            return False       # fell behind the frontier
        reach = max(reach, i + jump)
    return True
Time
O(n)
Space
O(1)

What goes wrong

The DP formulation is correct but O(n²) and unnecessary once you see the greedy invariant.