Sliding Window LeetCode Problems: All 116,
With Python Solutions

Every problem in this library that LeetCode tags Sliding Window. 102 of them carry a complete Python solution, a worked example and the time and space complexity of the approach.

Easy
12
Medium
74
Hard
30
1 pattern

How Sliding Window problems are solved

A tag names the subject, not the method. These pattern hubs cover the techniques that actually solve Sliding Window problems — each one explains the approach, gives a Python template and states its complexity.

Eyes only

When the Sliding Window problem arrives live.

In the live round, Stealth Interview reads the problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer says. It's a desktop app for macOS and Windows, invisible to screen sharing.

Sliding Window problems by difficulty

Problems with a complete Python solution are listed first, then by ascending problem number.

Easy (12)

Easy problems
No.Problem
0219Contains Duplicate II
0594Longest Harmonious Subsequence
0643Maximum Average Subarray I
1652Defuse the Bomb
1763Longest Nice Substring
1876Substrings of Size Three with Distinct Characters
1984Minimum Difference Between Highest and Lowest of K Scores
2269Find the K-Beauty of a Number
2379Minimum Recolors to Get K Consecutive Black Blocks
2760Longest Even Odd Subarray With Threshold
2932Maximum Strong Pair XOR I
1176Diet Plan PerformancePremium

Medium (74)

Medium problems
No.Problem
0003Longest Substring Without Repeating Characters
0187Repeated DNA Sequences
0209Minimum Size Subarray Sum
0395Longest Substring with At Least K Repeating Characters
0413Arithmetic Slices
0424Longest Repeating Character Replacement
0438Find All Anagrams in a String
0567Permutation in String
0658Find K Closest Elements
0713Subarray Product Less Than K
0718Maximum Length of Repeated Subarray
0837New 21 Game
0904Fruit Into Baskets
0930Binary Subarrays With Sum
0978Longest Turbulent Subarray
1004Max Consecutive Ones III
1016Binary String With Substrings Representing 1 To N
1031Maximum Sum of Two Non-Overlapping Subarrays
1040Moving Stones Until Consecutive II
1052Grumpy Bookstore Owner
1156Swap For Longest Repeated Character Substring
1208Get Equal Substrings Within Budget
1234Replace the Substring for Balanced String
1248Count Number of Nice Subarrays
1297Maximum Number of Occurrences of a Substring
1343Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold
1358Number of Substrings Containing All Three Characters
1423Maximum Points You Can Obtain from Cards
1438Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
1456Maximum Number of Vowels in a Substring of Given Length
1477Find Two Non-overlapping Sub-arrays Each With Target Sum
1493Longest Subarray of 1's After Deleting One Element
1658Minimum Operations to Reduce X to Zero
1695Maximum Erasure Value
1838Frequency of the Most Frequent Element
1839Longest Substring Of All Vowels in Order
1871Jump Game VII
1888Minimum Number of Flips to Make the Binary String Alternating
2024Maximize the Confusion of an Exam
2090K Radius Subarray Averages
2110Number of Smooth Descent Periods of a Stock
2134Minimum Swaps to Group All 1's Together II
2260Minimum Consecutive Cards to Pick Up
2271Maximum White Tiles Covered by a Carpet
2401Longest Nice Subarray
2411Smallest Subarrays With Maximum Bitwise OR
2461Maximum Sum of Distinct Subarrays With Length K
2516Take K of Each Character From Left and Right
2537Count the Number of Good Subarrays
2555Maximize Win From Two Segments
2653Sliding Subarray Beauty
2730Find the Longest Semi-Repetitive Substring
2747Count Zero Request Servers
2762Continuous Subarrays
2779Maximum Beauty of an Array After Applying Operation
2799Count Complete Subarrays in an Array
2831Find the Longest Equal Subarray
2841Maximum Sum of Almost Unique Subarray
2875Minimum Size Subarray in Infinite Array
2904Shortest and Lexicographically Smallest Beautiful String
2958Length of Longest Subarray With at Most K Frequency
2962Count Subarrays Where Max Element Appears at Least K Times
2981Find Longest Special Substring That Occurs Thrice I
2982Find Longest Special Substring That Occurs Thrice II
0159Longest Substring with At Most Two Distinct CharactersPremium
0340Longest Substring with At Most K Distinct CharactersPremium
0487Max Consecutive Ones IIPremium
1100Find K-Length Substrings With No Repeated CharactersPremium
1151Minimum Swaps to Group All 1's TogetherPremium
1852Distinct Numbers in Each SubarrayPremium
1918Kth Smallest Subarray SumPremium
2067Number of Equal Count SubstringsPremium
2107Number of Unique Flavors After Sharing K CandiesPremium
2743Count Substrings Without Repeating CharacterPremium

Hard (30)

Hard problems
No.Problem
0030Substring with Concatenation of All Words
0076Minimum Window Substring
0220Contains Duplicate III
0239Sliding Window Maximum
0480Sliding Window Median
0632Smallest Range Covering Elements from K Lists
0689Maximum Sum of 3 Non-Overlapping Subarrays
0862Shortest Subarray with Sum at Least K
0992Subarrays with K Different Integers
0995Minimum Number of K Consecutive Bit Flips
1044Longest Duplicate Substring
1425Constrained Subsequence Sum
1499Max Value of Equation
1610Maximum Number of Visible Points
1703Minimum Adjacent Swaps for K Consecutive Ones
2009Minimum Number of Operations to Make Array Continuous
2106Maximum Fruits Harvested After at Most K Steps
2156Find Substring With Given Hash Value
2302Count Subarrays With Score Less Than K
2398Maximum Number of Robots Within Budget
2444Count Subarrays With Fixed Bounds
2528Maximize the Minimum Powered City
2781Length of the Longest Valid Substring
2902Count of Sub-Multisets With Bounded Sum
2935Maximum Strong Pair XOR II
2953Count Complete Substrings
2968Apply Operations to Maximize Frequency Score
0683K Empty SlotsPremium
0727Minimum Window SubsequencePremium
2524Maximum Frequency Score of a SubarrayPremium