AlgoViz
HomeSliding Window

Sliding Window

A window that grows and shrinks over a run of elements.

0/ 20 understood · 0%
Walkthroughs
16
Problems
20
Start here
20 shown
  1. Best Time to Buy & Sell StockTrack the lowest price behind youEasy
  2. Maximum Sum Subarray of Size KFixed window · add one, drop oneEasy
  3. Longest Substring Without Repeating CharactersVariable window · jump the left edge past repeatsMedium
  4. Longest Repeating Character ReplacementWindow is valid while (size − maxFreq) ≤ kMedium
  5. Minimum Window SubstringSmallest window covering all needed charactersHard
  6. Practice problems
  7. Max Consecutive Ones IIILongest window holding at most k zerosMedium
  8. Fruit Into BasketsAt most two distinct valuesMedium
  9. Binary Subarrays With SumAt most goal, minus at most goal-1Hard
  10. Count number of Nice subarraysOdd numbers are 1s in disguiseHard
  11. Number of Substrings Containing All Three CharactersCount from the last valid startHard
  12. Maximum Points You Can Obtain from CardsMinimise the middle window insteadMedium
  13. Longest Substring With At Most K Distinct CharactersShrink while the map holds too many keysHard
  14. Subarrays with K Different IntegersatMost(k) minus atMost(k-1), againMedium
  15. Minimum Window SubsequenceWalk forward to match, backward to tightenHard
  16. Max Sum Subarray of Size KSlide a fixed window, add one and drop oneMedium
  17. Max Sum of Distinct Subarrays, Size KFixed window plus a frequency mapMedium
  18. Max Points From CardsSame idea: minimise the untaken middleMedium
  19. Variable-Size WindowGrow while valid, shrink when brokenMedium
  20. Longest Substring Without RepeatsJump the left edge past the previous copyMedium
  21. Permutation in StringFixed window, compare frequency countsMedium