Given an integer array nums where each element is the maximum jump length from that position, determine whether you can reach the last index starting from index 0.
Example
Input nums = [2,3,1,1,4]
Output true
Key Pointers
Track the furthest index reachable so far instead of simulating every possible jump path.
If the current index ever exceeds the furthest reachable index, that position is unreachable and the answer is false.
A single greedy left-to-right pass is enough — no need to try every jump length from every position.
Step-by-Step Analysis
Initialize farthest = 0.
For each index i, value n in nums: if i > farthest, return False — this index can't be reached.
Otherwise update farthest = max(farthest, i + n).
If the loop completes, return True.
Complexity
Time: O(n) — Space: O(1)
Code
def canJump(nums: list[int]) -> bool:
farthest = 0
for i, n in enumerate(nums):
if i > farthest:
return False
farthest = max(farthest, i + n)
return True
Code Explanation
How the solution above works, piece by piece.
farthest = the furthest index reachable so far.
Walk left to right. If i > farthest, index i can't be reached, so neither can the end → False.
Otherwise, from i you can reach i + nums[i]; update farthest.
If the loop finishes, every index (including the last) was reachable → True.
One pass, O(1) space: no need to know which jumps, only how far they can get.
Visual Walkthrough
Running it on nums = [2, 3, 1, 1, 4]:
Blue marks everything reachable so far. From index 1 (value 3) the reach already covers the last index, so the answer is True.