10 Sliding Window Patterns For Coding Interviews
Heyy leetcoders! Sliding windows is commonly asked in interview as of one of the questions at most of the times.
DP, arrays, and mamny other topics can be optimised by sliding window.
Sliding Window transforms many O(n²) problems into O(n) by maintaining a dynamic range instead of recomputing subarrays from scratch.
I’ve compiled the 10 essential Sliding Window patterns you must know — each with practice problems that you help you master this domain.
Pattern 1: Fixed-Size Window
Used when the window size k is fixed.
Practice Problems:
- Maximum Average Subarray I
- Max Consecutive Ones III
- Maximum Sum of Distinct Subarrays With Length K
- Contains Duplicate II
Bonus Problems:
Pattern 2: Variable-Size Window (Expand + Shrink)
For conditions like sum ≥ K, distinct elements ≤ K, etc.
Practice Problems:
- Longest Substring Without Repeating Characters
- Minimum Size Subarray Sum
- Fruit Into Baskets
- Subarray Sum Equals K
- Binary Subarrays With Sum
Bonus Problems:
Pattern 3: Sliding Window with Frequency Map
Used for anagrams, permutations, character frequency matching.
Practice Problems:
- Permutation in String
- Find All Anagrams in a String
- Minimum Window Substring
- Longest Substring with At Most K Distinct Characters
- Longest Substring with At Most Two Distinct Characters
Bonus Problems:
Pattern 4: Longest / Shortest Substring With Condition
For substring max/min length based on constraints.
Practice Problems:
- Longest Repeating Character Replacement
- Max Consecutive Ones III
- Shortest Subarray With Sum at Least K
- Longest Subarray of 1s After Deleting One Element
- Maximum Erasure Value
Bonus Problems:
Pattern 5: Exactly K / At Most K Distinct Elements
For substring problems involving distinct characters.
Practice Problems:
- Subarrays with K Different Integers
- Longest Substring with At Most K Distinct Characters
- Longest Substring Without Repeating Characters
- Longest Repeating Character Replacement
- Fruit Into Baskets
Bonus Problems:
Pattern 6: Window With Sum / Product Constraints
For windows where total sum/product must follow a rule.
Practice Problems:
- Subarray Product Less Than K
- Minimum Size Subarray Sum
- Continuous Subarray Sum
- Subarray Sum Equals K
- Maximum Points You Can Obtain from Cards
Bonus Problems:
Pattern 7: Sliding Window with Monotonic Queue (Deque)
Optimal for max/min in each window.
Practice Problems:
- Sliding Window Maximum
- Sliding Window Median
- Sum of Subarray Minimums
- Constrained Subsequence Sum
- Shortest Subarray with Sum at Least K
Bonus Problems:
Pattern 8: Sliding Window + Prefix Sums
Used for cumulative or range-based window checks.
Practice Problems:
- Subarray Sum Equals K
- Continuous Subarray Sum
- Shortest Subarray With Sum at Least K
- Minimum Operations to Reduce X to Zero
- Find Pivot Index
Bonus Problems:
Pattern 9: Sliding Window + Two Pointers
Useful when window depends on sort order or value differences.
Practice Problems:
- Longest Continuous Subarray With Absolute Diff <= Limit
- Longest Substring with At Most K Distinct Characters
- Minimum Window Substring
- Maximum Vowels in a Substring of Given Length
- Longest Subarray of 1s After Deleting One Element
Bonus Problems:
Pattern 10: Dual Windows (Two Simultaneous Windows)
Used when two separate windows track different conditions.
Practice Problems:
- Substring With Concatenation of All Words
- Number of Subarrays Containing All Three Numbers
- Longest Nice Subarray
- Substring With Largest Variance
- Longest Substring Without Repeating Characters
Bonus Problems:
Would love to indulge your patterns, Qns and add-ons, do share your thoughts!
If you found this post useful please upvote.
Happy Coding!!
Links to my other shares you might find useful:
Complete Plan (1st yr-3rd yr) (DSA + Projects + Core CS)
15 Core Greedy Patterns For Coding Interviews
15 DP variations for Interviews
Amazon ❤️ Trees; Google ❤️ Graphs; Microsoft ❤️ DP; Meta ❤️ fusion => interviewers ❤️ DSA
10 N-ary Tree Problems For Interviews That Define Google-Level Thinking

