A deque finds the best score to jump from
transcript
A hiking trail has checkpoints. Each one has points. You jump at most three ahead.
Best of a checkpoint is its points. Plus the best total in reach. The reach is a sliding window. So a deque finds that best.
Checkpoint zero scores two. Checkpoint one scores minus two. Checkpoint two reaches back to zero. Eight. Checkpoints three and four score seven and five. Checkpoint five reaches back to two. Thirteen.
The deque holds positions. Their totals fall, front to back. Drop the front when it is out of reach. Drop weaker totals from the back.
Each checkpoint joins once. Each leaves at most once. The whole trail costs O of n.
Checkpoint i looks back three. Checkpoint i plus one looks back three too. Its window lost one old checkpoint. That old one leaves the front. A new one joins the back.
Compute from the front. Then trim and add. Full breakdown in the lecture.