Fixed vs Variable Window

Two window types

Fixed windows have a constant size kk. You slide the window one position at a time, adding the new element and removing the old. Use this for "maximum sum of kk consecutive elements" problems.

Variable windows expand and shrink based on conditions. Expand the right pointer until a condition breaks, then shrink from the left until it's valid again. Use this for "longest substring with at most kk distinct characters" problems.

The key difference: fixed windows always move both pointers together, variable windows move them independently based on constraints.