DSA Master › Topic 3

Sliding Window

A window [l, r] moves across a string or array. Expand r to take in elements, and shrink l when the window breaks a constraint. Each element enters and leaves once, so the whole pass is O(n).

Concepts

How to recognise it

Common pitfalls

Problems

  1. Maximum Average Subarray I (Easy)
  2. Longest Substring Without Repeating Characters (Medium)
  3. Longest Repeating Character Replacement (Medium)
  4. Permutation in String (Medium)
  5. Find All Anagrams in a String (Medium)
  6. Minimum Window Substring (Hard)
  7. Sliding Window Maximum (Hard)
  8. Max Consecutive Ones III (Medium)
  9. Fruit Into Baskets (Medium)
  10. Subarray Product Less Than K (Medium)