Sliding Window
54 problems · 38 with full explanations
5 Easy27 Medium8 Hard
The sliding window technique maintains a dynamic sub-array (or substring) of interest, expanding the right boundary and shrinking the left boundary based on a constraint. It reduces O(n²) substring enumeration to O(n). Track state (frequency map, sum, distinct count) incrementally.
How to practice
To practice Sliding Window problems effectively, start with the Easy problems listed below, trace through each solution on paper, then re-implement without looking. When you can recognise the sliding window pattern within 30 seconds of reading a new problem, move on to Medium difficulty. Use the related topic pages and our study guide for a structured progression.
Start here (Easy + explained)
All Sliding Window problems
- 30.Substring with Concatenation of All WordsHard
- 76.Minimum Window SubstringHard
- 219.Contains Duplicate IIEasy
- 220.Contains Duplicate IIIHard
- 239.Sliding Window MaximumHard
- 567.Permutation in StringMedium
- 594.Longest Harmonious SubsequenceEasy
- 632.Smallest Range Covering Elements from K ListsHard
- 689.Maximum Sum of 3 Non-Overlapping SubarraysUnknown
- 862.Shortest Subarray with Sum at Least KHard
- 904.Fruit Into BasketsMedium
- 995.Minimum Number of K Consecutive Bit FlipsUnknown
- 1052.Grumpy Bookstore OwnerMedium
- 1248.Count Number of Nice SubarraysMedium
- 1358.Number of Substrings Containing All Three CharactersMedium
- 1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to LimitMedium
- 1493.Longest Subarray of 1's After Deleting One ElementMedium
- 1695.Maximum Erasure ValueMedium
- 1888.Minimum Number of Flips to Make the Binary String AlternatingUnknown
- 2009.Minimum Number of Operations to Make Array ContinuousUnknown
- 2090.K Radius Subarray AveragesMedium
- 2106.Maximum Fruits Harvested After at Most K StepsUnknown
- 2134.Minimum Swaps to Group All 1's Together IIMedium
- 2271.Maximum White Tiles Covered by a CarpetUnknown
- 2302.Count Subarrays With Score Less Than KHard
- 2379.Minimum Recolors to Get K Consecutive Black BlocksEasy
- 2401.Longest Nice SubarrayMedium
- 2411.Smallest Subarrays With Maximum Bitwise ORMedium
- 2444.Count Subarrays With Fixed BoundsHard
- 2461.Maximum Sum of Distinct Subarrays With Length KMedium
- 2516.Take K of Each Character From Left and RightMedium
- 2537.Count the Number of Good SubarraysMedium
- 2762.Continuous SubarraysMedium
- 2799.Count Complete Subarrays in an ArrayMedium
- 2962.Count Subarrays Where Max Element Appears at Least K TimesMedium
- 2981.Find Longest Special Substring That Occurs Thrice IMedium
- 3013.Divide an Array Into Subarrays With Minimum Cost IIUnknown
- 3097.Shortest Subarray With OR at Least K IIMedium
- 3208.Alternating Groups IIUnknown
- 3234.Count the Number of Substrings With Dominant OnesEasy
- 3254.Find the Power of K-Size Subarrays IMedium
- 3306.Count of Substrings Containing Every Vowel and K Consonants IIMedium
- 3318.Find X-Sum of All K-Long Subarrays IEasy
- 3321.Find X-Sum of All K-Long Subarrays IIUnknown
- 3346.Maximum Frequency of an Element After Performing Operations IMedium
- 3347.Maximum Frequency of an Element After Performing Operations IIUnknown
- 3354.Make Array Elements Equal to ZeroUnknown
- 3381.Maximum Subarray Sum With Length Divisible by KMedium
- 3445.Maximum Difference Between Even and Odd Frequency IIMedium
- 3477.Fruits Into Baskets IIMedium
- 3479.Fruits Into Baskets IIIUnknown
- 3487.Maximum Unique Subarray Sum After DeletionMedium
- 3567.Minimum Absolute Difference in Sliding SubmatrixUnknown
- 3578.Count Partitions With Max-Min Difference at Most KUnknown