[go: up one dir, main page]

0% found this document useful (0 votes)
1 views5 pages

Sliding Window

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views5 pages

Sliding Window

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SLIDING WINDOW

TOPIC 1: Fixed Size Sliding Window


(Foundation)
What You Learn
Window of size k
Maintain running sum
Add right, remove left
O(n) optimization from O(n*k)

🟢 Easy
643 – Maximum Average Subarray I
1456 – Maximum Number of Vowels in a Substring of Given Length
1343 – Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold

🟡 Medium
1423 – Maximum Points You Can Obtain from Cards
1052 – Grumpy Bookstore Owner

🔴 Hard
TOPIC 2: Variable Size Sliding Window (Grow
& Shrink)
This is the MOST IMPORTANT sliding window pattern.

What You Learn


Two pointers (left, right)
Expand right
Shrink left when invalid
Longest/shortest valid subarray

🟢 Easy
209 – Minimum Size Subarray Sum

🟡 Medium
3 – Longest Substring Without Repeating Characters ⭐
1004 – Max Consecutive Ones III
424 – Longest Repeating Character Replacement
1493 – Longest Subarray of 1’s After Deleting One Element
904 – Fruit Into Baskets
713 – Subarray Product Less Than K
1208 – Get Equal Substrings Within Budget
1498 – Number of Subsequences That Satisfy the Given Sum Condition

🔴 Hard

76 – Minimum Window Substring (MUST MASTER)
992 – Subarrays with K Different Integers
1358 – Number of Substrings Containing All Three Characters

TOPIC 3: Sliding Window + Frequency Map


What You Learn
Maintain character count
Use HashMap / array[26]
Track valid condition
Maintain distinct count

🟡 Medium
340 – Longest Substring with At Most K Distinct Characters
438 – Find All Anagrams in a String
567 – Permutation in String
930 – Binary Subarrays With Sum

🔴 Hard
76 – Minimum Window Substring
992 – Subarrays with K Different Integers

TOPIC 4: Sliding Window + Monotonic Deque


Used when problem asks:

Maximum in window
Minimum in window
Shortest subarray with condition

🟡 Medium
239 – Sliding Window Maximum ⭐
🔴 Hard
862 – Shortest Subarray with Sum at Least K
1438 – Longest Continuous Subarray With Absolute Diff ≤ Limit

TOPIC 5: Sliding Window + Prefix Sum


Transformation
Some problems look different but reduce to window logic.

🟡 Medium
1658 – Minimum Operations to Reduce X to Zero
1423 – Maximum Points You Can Obtain from Cards

🟤 TOPIC 6: Circular Sliding Window


🟡 Medium
2134 – Minimum Swaps to Group All 1's Together II

🔴 TOPIC 7: Advanced Window Counting


Technique
Counting number of valid subarrays.

🟡 Medium
1248 – Count Number of Nice Subarrays
930 – Binary Subarrays With Sum

🔴 Hard
992 – Subarrays with K Different Integers

MASTERY LEVEL PROBLEMS (FINAL BOSS


SET)
If a student solves these comfortably → MASTER LEVEL

3
76
239
992
862
1438
424

KEY TAKEAWAYS FOR SLIDING WINDOW


Recognize When to Use It
Look for keywords:

"Substring"
"Subarray"
"Contiguous"
"Longest"
"Shortest"
"At most K"
"At least K"

Think Sliding Window immediately.

2) Fixed vs Variable
If window size is given → Fixed Window
If condition-based → Variable Window

3)Generic Variable Window Template


left = 0

for right in range(n):

include nums[right]

while window invalid:

remove nums[left]

left += 1

update answer

4) Two Main Question Types


1. Longest valid subarray
2. Shortest valid subarray

5) For Counting Problems


Use:

atMost(k) - atMost(k-1)

Very important trick (used in 992, 1248).

6)When Sliding Window FAILS


If:

Negative numbers exist


Sum condition tricky

Try Prefix Sum instead.

AFTER COMPLETING THIS ROADMAP


Student will:

✔ Master two-pointer technique


✔ Solve 95% substring problems
✔ Handle frequency-map windows
✔ Solve deque-based window problems
✔ Crack FAANG sliding window questions

You might also like