Sliding Window

Turn O(n·k) scans into one O(n) pass by reusing the work you already did.

5 lessons · ~50 min · free

By the end you can

  1. The work you keep redoing8 minWhere the pattern comes from: overlapping subarrays and the waste in the brute force.
  2. Fixed-size windows10 minThe subtract-and-add slide, the standard template, and the classic off-by-ones.
  3. Variable-size windows12 minGrow the right edge, shrink the left, and keep an invariant true the whole time.
  4. Shortest windows and counting11 minFlip the shrink rule for minimum-length answers, and count windows with the at-most trick.
  5. Spotting window problems9 minThe cues that say sliding window, the cases where it silently breaks, and both templates side by side.

The account is free and so is every lesson. It unlocks the courses and saves your progress.

Practice it after

The final lesson links here too: real interview questions that test this pattern, in an editor with execution and AI feedback.