mediumDynamic ProgrammingDynamic Programming

Jump Game

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

Signals to notice

can you reach the last indexjump at most nums[i] stepsreachability check

Brute force first

BFS/DFS from index 0, trying all jump distances — in the worst case due to redundant state exploration. 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: maintain the farthest index you can reach. Scan left to right — if the current index exceeds your max reach, you're stuck. If max reach ≥ last index, you can make it. The goal is not to be clever for its own sake, but to remember the one relationship that keeps the solution grounded as you move forward.

What must stay true

maxReach = max(maxReach, i + nums[i]) at each step. If i > maxReach at any point, position i is unreachable and so is everything after it. If that remains true after every update, the rest of the reasoning has a stable place to stand.

Easy way to go wrong

Trying to track the actual jump path — you don't need it. Only the farthest reachable index matters for the yes/no answer. When the code becomes mechanical before the idea is clear, small edge cases start breaking the whole story.

Dynamic Programming Pattern