8. Sliding Window

Fixed and variable windows over arrays and strings.

🎬 Episode 10: video coming soon
Your progress0 of 14
2easy
10medium
2hard

Understand the topic

A sliding window is a frame over a contiguous part of an array or string. Instead of recomputing every subarray, you add the element that enters and remove the one that leaves.

Fixed windows keep the same size (k). Variable windows grow on the right and shrink from the left while a rule is broken. For "exactly K" questions, compute atMost(K) - atMost(K - 1).

#ProblemPatternLevel
1 Maximum Average Subarray I #643 Fixed window Easy LeetCode β†—
2 Contains Duplicate II #219 Fixed window + HashSet Easy LeetCode β†—
3 Longest Substring Without Repeating Characters #3 Variable window Medium LeetCode β†—
4 Longest Repeating Character Replacement #424 Variable window + max frequency Medium LeetCode β†—
5 Permutation in String #567 Fixed window + counts Medium LeetCode β†—
6 Find All Anagrams in a String #438 Fixed window + counts Medium LeetCode β†—
7 Minimum Size Subarray Sum #209 Variable window (shrink while valid) Medium LeetCode β†—
8 Max Consecutive Ones III #1004 Variable window with budget Medium LeetCode β†—
9 Fruit Into Baskets #904 Variable window, at most 2 kinds Medium LeetCode β†—
10 Maximum Number of Vowels in a Substring of Given Length #1456 Fixed window Medium LeetCode β†—
11 Maximum Points You Can Obtain from Cards #1423 Window on the complement Medium LeetCode β†—
12 Count Number of Nice Subarrays #1248 atMost(k) βˆ’ atMost(kβˆ’1) Medium LeetCode β†—
13 Minimum Window Substring #76 Variable window with need counts Hard LeetCode β†—
14 Subarrays with K Different Integers #992 atMost(k) βˆ’ atMost(kβˆ’1) Hard LeetCode β†—

Work top to bottom β€” each list goes from easy to hard. Try a problem for at least 15 minutes before opening a hint. Ticks are saved in your browser.