AlgoScope

Fixed-Size Window

A window of size k. Add what enters, subtract what leaves, never re-add the middle.

Sliding window, algorithm, beginner
The window slides right. 2 leaves and 1 enters, giving a sum of 7. The best is still 8.active 1-32011521334257617leftright
The window slides right. 2 leaves and 1 enters, giving a sum of 7. The best is still 8.active 1-32011521334257617leftright

Sliding Window: Largest sum of 3 in a row

Decision, step 2 of 7

2 leaves and 1 enters, so the sum is 7. The best stays at 8.

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.