Fixed-Size Window
A window of size k. Add what enters, subtract what leaves, never re-add the middle.
Decision · step 2 of 7Sliding Window: Largest sum of 3 in a row
2 leaves and 1 enters, so the sum is 7. The best stays at 8.
What you will see
The frame is always k wide; the running sum updates with two arrows.
Cost
| Best | O(n) |
|---|---|
| Average | O(n) |
| Worst | O(n) |
| Space | O(1) |
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.
Screen readers: Cells announce index, value and whether they are inside the window; each step announces the window bounds and the running value.
Reduced motion: The window frame snaps to its new bounds with a crossfade.
Before this
Taught by the same lesson
Sliding Window covers these too, in the same run.