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
- See why recomputing overlapping windows wastes work, and what reuse looks like
- Write the fixed-size template without off-by-one errors
- Drive a variable-size window with a grow/shrink invariant
- Handle shortest-window and count-the-windows variants
- Decide in under a minute whether a problem is a window problem
Lessons
Start the course- The work you keep redoing8 minWhere the pattern comes from: overlapping subarrays and the waste in the brute force.
- Fixed-size windows10 minThe subtract-and-add slide, the standard template, and the classic off-by-ones.
- Variable-size windows12 minGrow the right edge, shrink the left, and keep an invariant true the whole time.
- Shortest windows and counting11 minFlip the shrink rule for minimum-length answers, and count windows with the at-most trick.
- 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.