A window of constant width
A fixed size sliding window examines every contiguous block of exactly k elements. Rather than recomputing each block from scratch, you maintain a running aggregate and update it incrementally as the window slides forward by one position.
The slide step
When the window advances one step, exactly two things change:
- The element entering on the right is added to the aggregate.
- The element leaving on the left is removed from it.
This add one, drop one update is constant work per step, so the whole scan stays linear regardless of the window width.
Building the first window
You typically prime the window by summing the first k elements directly. After that initial fill, every later position is just one entering and one leaving update, and you record the aggregate after each slide.
Key idea
A fixed window keeps a running aggregate and only adds the entering element and drops the leaving one per step, turning what looks like many overlapping sums into a single linear sweep.