QuestionsDSA

Jump Game

Greedy / One-PassMediumDSA

Each element is the max jump length from that index. Starting at index 0, can you reach the last index?

What it tests

Greedy reachability (track the farthest index reachable) versus an exponential DFS or heavier DP.

Approach & answer

Track the farthest index reachable so far. Iterate left to right; if the current index i is beyond farthest, you can never land here, so return false; otherwise extend farthest = max(farthest, i + nums[i]). If farthest ever reaches the last index, return true. Greedy works because reachability is monotonic — if you can reach index i you can reach everything up to farthest, so there's never a reason to 'save' a jump. Signal: 'can you reach / minimum steps to reach the end' → greedy farthest-reach in one pass, which turns an O(2^n) branch search into O(n).

Use this technique when

'Can you reach the end', minimum jumps, interval covering — anywhere a running reachable-frontier suffices.

Complexity

Time O(n), Space O(1)

References

js