1.Fixed-size window (e.g. max sum of size-k subarray)
A fixed-size window of exactly k elements slides across an array one step at a time — only the element leaving and the element entering change the running total, so nothing needs to be resummed.
Key features
- Turns an O(n × k) brute force ("resum every window") into O(n) — each element enters and leaves the window exactly once
- The window size k stays the same for the entire scan — it never grows or shrinks
- Needs one O(k) pass up front to build the first window before sliding begins
A fixed window updates by subtracting the outgoing element and adding the incoming one — resumming the whole window at every position is the O(n × k) trap this pattern exists to avoid.