2
3
1
1
4
[0][1][2][3][4]
Greedy · layer-by-layer farthest reach
▸1given nums2jumps ← 0; curEnd ← 0; farthest ← 03for i ← 0 to n − 2:4 farthest = max(farthest, i + nums[i])5 if i == curEnd:6 jumps++; curEnd ← farthest7 if curEnd ≥ n − 1: break8return jumps
state
- n5
- last4
- nums[2, 3, 1, 1, 4]