AlgoScope

Sliding Window

Keep a contiguous range and update its summary as it moves, instead of rescanning it.

Sliding window, technique, intermediate
The window slides right. 1 leaves and 7 enters, giving a sum of 12. That is a new best.active 4-62011521334257617leftright
The window slides right. 1 leaves and 7 enters, giving a sum of 12. That is a new best.active 4-62011521334257617leftright

Sliding Window: Largest sum of 3 in a row

Decision, step 5 of 7

1 leaves and 7 enters, so the sum is 12. That beats the best so far.

Cost

Best
O(n)
Average
O(n)
Worst
O(n)
Space
O(1)

Leads to

Topics that need this one first.

Taught by the same lesson

Sliding Window covers these too, in the same run.