Hard · Greedy Range Expansion
Understand → Visualise → Practice.
Every jump reaches a range of indices. Scan the current range while tracking the farthest next boundary, then commit one jump when the range ends.
`end` is the boundary reachable with the current jump count; `farthest` builds the next boundary.
Update farthest = max(farthest, i + nums[i]).
Increment jumps and set end = farthest.
The last index needs no jump out.
O(n) time and O(1) space.
Choosing the locally largest jump value is wrong; choose the option that reaches farthest after accounting for its index.
Read the full guide first: Greedy Algorithms and Interval Patterns.
Guest mode lets you understand, visualise and run the sample tests. Create a free account to submit and save your solutions.