Section Recap

Summary of sliding window techniques.

Fixed and variable sliding windows, plus monotonic deque for range max.

Fixed: Initialize size kk, slide by add/remove. O(n)O(n) time.

Variable: Expand right, shrink left when invalid. Each element touched once.

Patterns:

  • Longest/shortest with condition → Variable
  • All windows size kk → Fixed
  • Max/Min in each window → Monotonic deque

Transforms O(n2)O(n^2) to O(n)O(n) by reusing computation.