Sliding Window
A sliding window keeps a contiguous range over an array or string and expands or shrinks its two edges to maintain a constraint, turning an O(n²) scan of every subarray into a single O(n) pass. Use it for longest / shortest / contains questions about a contiguous subarray or substring.
15 LeetCode problems solved with the Sliding Window pattern. Practice them with spaced repetition so the pattern sticks.
- Count the Number of Good SubarraysMEDIUM · O(n)
- Find All Anagrams in a StringMEDIUM · O(n)
- Longest Continuous Increasing SubsequenceEASY · O(n)
- Longest Repeating Character ReplacementMEDIUM · O(n)
- Longest Subarray of 1's After Deleting One ElementMEDIUM · O(n)
- Longest Substring Without Repeating CharactersMEDIUM · O(n)
- Max Consecutive Ones IIIMEDIUM · O(n)
- Maximum Average Subarray IEASY · O(n)
- Maximum Erasure ValueMEDIUM · O(n)
- Maximum Number of Vowels in a Substring of Given LengthMEDIUM · O(n)
- Minimum Size Subarray SumMEDIUM · O(n)
- Minimum Window SubstringHARD · O(m + n)
- Permutation in StringMEDIUM · O(n)
- Sliding Window MaximumHARD · O(n)
- Substring with Concatenation of All WordsHARD · O(n * L)
See the full solution
The complete approach, reference solutions in 5 languages, and a step-by-step visualization — then add this problem to your spaced-repetition schedule.
Start free →