algorythms
All Patterns
Pattern 1

Sliding Window

37291584window

Maintain a window over a contiguous subarray or substring, expanding or shrinking it to satisfy a constraint. Avoids recomputing from scratch on every step.

Time

O(n)

Space

O(1) or O(k)

Recognize it when

  • Find max/min/average of contiguous subarrays of size k
  • Longest/shortest subarray/substring satisfying a condition
  • Problem mentions "contiguous" sequence
  • "At most K distinct elements" or "exactly K" pattern
Progress0/7
0 solved0 attempted