Engrain by ByteRush

DSA.06.02 Mid-levelCore — asked often

Pattern 2: Sliding window

Comes up in: DSA

This concept is being written. It gets the full five steps — explanation, predict, interview angle, practice with tests, and review cards. Here is exactly what it will cover, so you can study it elsewhere in the meantime.

What it covers

  • fixed vs variable window
  • expand/shrink template with a hash map
  • "longest/shortest subarray with condition"
  • when windows fail (negative numbers → prefix sums)

Words you will know

sliding window

What you will practise

  • max-sum-subarray-k (E)
  • buy-sell-stock (E)
  • longest-substring-no-repeat (M)
  • longest-repeating-char-replacement (M)
  • permutation-in-string (M)
  • fruit-baskets (M)
  • min-window-substring (H)

Interview questions this answers

  • How do you recognise a sliding-window problem?
  • Why does the sliding window fail with negative numbers, and what do you use instead?