Problem Statement
Jump Game
You are given an integer array nums. You start at the first index. Each number tells you the most squares you are allowed to jump forward from that spot. Return true if you can reach the last index, or false otherwise.
Signals to notice
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.
Trace it on nums=[2,3,1,1,4]
init: farthest=0 i=0: 0>farthest? no -> farthest=max(0, 0+2)=2 i=1: 1>2? no -> farthest=max(2, 1+3)=4 (already reaches last index 4) i=2: 2>4? no -> farthest=max(4, 2+1)=4 i=3: 3>4? no -> farthest=max(4, 3+1)=4 i=4: 4>4? no -> farthest=max(4, 4+4)=8 loop ends, no index exceeded farthest -> return True
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.
Shape of the loop
farthest = 0
for i in 0..n-1:
if i > farthest: return False # index i unreachable
farthest = max(farthest, i + nums[i])
return TruePseudocode only — the full worked solution lives in the Solution tab.
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.