HomeSliding Window
Sliding Window
A window that grows and shrinks over a run of elements.
20 shown
- Best Time to Buy & Sell StockTrack the lowest price behind youanimatedEasy
- Maximum Sum Subarray of Size KFixed window · add one, drop oneanimatedEasy
- Longest Substring Without Repeating CharactersVariable window · jump the left edge past repeatsanimatedMedium
- Longest Repeating Character ReplacementWindow is valid while (size − maxFreq) ≤ kanimatedMedium
- Minimum Window SubstringSmallest window covering all needed charactersanimatedHard
- Practice problems
- Max Consecutive Ones IIILongest window holding at most k zerosanimatedMedium
- Fruit Into BasketsAt most two distinct valuesanimatedMedium
- Binary Subarrays With SumAt most goal, minus at most goal-1animatedHard
- Count number of Nice subarraysOdd numbers are 1s in disguiseanimatedHard
- Number of Substrings Containing All Three CharactersCount from the last valid startanimatedHard
- Maximum Points You Can Obtain from CardsMinimise the middle window insteadanimatedMedium
- Longest Substring With At Most K Distinct CharactersShrink while the map holds too many keysanimatedHard
- Subarrays with K Different IntegersatMost(k) minus atMost(k-1), againMedium
- Minimum Window SubsequenceWalk forward to match, backward to tightenHard
- Max Sum Subarray of Size KSlide a fixed window, add one and drop oneanimatedMedium
- Max Sum of Distinct Subarrays, Size KFixed window plus a frequency mapMedium
- Max Points From CardsSame idea: minimise the untaken middleanimatedMedium
- Variable-Size WindowGrow while valid, shrink when brokenMedium
- Longest Substring Without RepeatsJump the left edge past the previous copyanimatedMedium
- Permutation in StringFixed window, compare frequency countsanimatedMedium