Jump Game

LeetCode: https://leetcode.com/problems/jump-game/

You are given an integer array nums where nums[i] is your maximum jump length from index i. Return true if you can reach the last index.

1def canJump(nums: List[int]) -> bool:
2 farthest = 0
3 for i, x in enumerate(nums):
4 if i > farthest:
5 return False
6 farthest = max(farthest, i + x)
7 return True
i
2
0
3
1
1
2
1
3
4
4
farthest=2
Step 1 / 3
Step 1:
Track farthest reachable index while scanning.
Pointers: i=0
Focus: select @ [0]
farthest=2