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:

Bonus Problems:


Pattern 2: Variable-Size Window (Expand + Shrink)

For conditions like sum ≥ K, distinct elements ≤ K, etc.

Practice Problems:

Bonus Problems:


Pattern 3: Sliding Window with Frequency Map

Used for anagrams, permutations, character frequency matching.

Practice Problems:

Bonus Problems:


Pattern 4: Longest / Shortest Substring With Condition

For substring max/min length based on constraints.

Practice Problems:

Bonus Problems:


Pattern 5: Exactly K / At Most K Distinct Elements

For substring problems involving distinct characters.

Practice Problems:

Bonus Problems:


Pattern 6: Window With Sum / Product Constraints

For windows where total sum/product must follow a rule.

Practice Problems:

Bonus Problems:


Pattern 7: Sliding Window with Monotonic Queue (Deque)

Optimal for max/min in each window.

Practice Problems:

Bonus Problems:


Pattern 8: Sliding Window + Prefix Sums

Used for cumulative or range-based window checks.

Practice Problems:

Bonus Problems:


Pattern 9: Sliding Window + Two Pointers

Useful when window depends on sort order or value differences.

Practice Problems:

Bonus Problems:


Pattern 10: Dual Windows (Two Simultaneous Windows)

Used when two separate windows track different conditions.

Practice Problems:

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

Comments (8)