Can you reach the last stop
transcript
A bus line has six stops. Each stop lets you hop ahead. Can you reach the last one? A hop can be shorter than the limit.
Keep the farthest stop reached. If a stop is beyond it, you are stuck. Stop plus hops is how far that stop reaches. Else farthest becomes the larger of itself and stop plus hops.
The hops are two, three, one, one, zero, four. Stop zero has hops two. Farthest is two. Stop one has hops three. Farthest is four. Stops two, three and four add nothing. Stop five is beyond four. Stuck. The last stop cannot be reached.
The reachable stops form an unbroken run. A hop can be shorter than its limit. So the farthest stop says it all. There is no choice to undo. That is greedy, in its simplest form.
One number can replace a search. Keep it up to date at every stop. Full breakdown in the lecture.