0% found this document useful (0 votes)
55 views4 pages

Sliding Window Pattern

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)
55 views4 pages

Sliding Window Pattern

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
You are on page 1/ 4

slidingwindowpattern

August 1, 2025

1 Sliding Window Pattern


->Fixed Size Window
->Variable size Window

2 Sliding Window Problems - Structured by Data Structures &


Window Types
2.1 1. Basic Sliding Window (No Extra Data Structure)
Pure two-pointer technique with simple conditions | # | Problem | Window Type | Platform |
Company | | - | ————————————————————————————————————
———————————————————– | ———– | ————- | —————– | | 1 | Maximum
Average Subarray I | Fixed | LeetCode 643 | Amazon, Microsoft | | 2 | Number of Sub-arrays of Size
K and Average >= Threshold | Fixed | LeetCode 1343 | Facebook | | 3 | Defanging an IP Address
| Fixed | LeetCode 1108 | Basic | | 4 | Find the K-Beauty of a Number | Fixed | LeetCode 2269
| Google | | 5 | Max Consecutive Ones | Variable | LeetCode 485 | Google, Amazon | | 6 | Max
Consecutive Ones II | Variable | LeetCode 487 | Google | | 7 | Longest Subarray of 1s After Deleting
One Element | Variable | LeetCode 1493 | Amazon | | 8 | Maximum Points You Can Obtain from
Cards | Variable | LeetCode 1423 | Amazon, Google |

2.2 2. Prefix Sum Based


When you need range sums or cumulative calculations

# Problem Window Type Platform Company


9 Range Sum Query - Immutable Fixed LeetCode 303 Amazon, Microsoft
10 Find Pivot Index Fixed LeetCode 724 Amazon, Facebook
11 Subarray Sum Equals K Variable LeetCode 560 Facebook, Amazon
12 Product of Array Except Self Fixed LeetCode 238 Amazon, Microsoft
13 Minimum Size Subarray Sum Variable LeetCode 209 Facebook, Amazon
14 Maximum Size Subarray Sum Equals k Variable LeetCode 325 Facebook
15 Continuous Subarray Sum Variable LeetCode 523 Facebook, Amazon
16 Subarray Sums Divisible by K Variable LeetCode 974 Amazon

1
2.3 3. HashMap/HashSet Based
For tracking frequencies, counts, or seen elements

Window
# Problem Type PlatformCompany
17 Find All Anagrams in a String Fixed LeetCodeAmazon,
438 Facebook
18 Permutation in String Fixed LeetCodeMicrosoft,
567 Amazon
19 Sliding Window Maximum Fixed LeetCodeAmazon,
239 Google
20 Contains Duplicate II Fixed LeetCodeAmazon,
219 Apple
21 Longest Substring Without Repeating Characters VariableLeetCodeAmazon,
3 Facebook
22 Longest Substring with At Most Two Distinct Characters VariableLeetCodeGoogle
159
23 Longest Substring with At Most K Distinct Characters VariableLeetCodeGoogle
340
24 Fruit Into Baskets VariableLeetCodeAmazon
904
25 Subarrays with K Different Integers VariableLeetCodeGoogle
992

2.4 4. Deque Based


For maintaining maximum/minimum efficiently in sliding windows

Window
# Problem Type PlatformCompany
26 Sliding Window Maximum Fixed LeetCodeAmazon,
239 Google
27 Sliding Window Minimum (Custom) Fixed Custom Google
28 Constrained Subsequence Sum Fixed LeetCodeGoogle
1425
29 Shortest Subarray with Sum at Least K VariableLeetCodeGoogle,
862 Facebook
30 Jump Game VI VariableLeetCodeAmazon
1696
31 Minimum Number of Taps to Open to Water a Garden VariableLeetCodeGoogle
1326

2.5 6. Two Data Structures Combined


2.5.1 HashMap + Prefix Sum

2
Window
# Problem Type Platform Company
38 Binary Subarrays With Sum Fixed LeetCodeAmazon
930
39 Count Number of Nice Subarrays Fixed LeetCodeAmazon
1248
40 Minimum Operations to Reduce X to Zero VariableLeetCodeAmazon,
1658 Facebook
41 Maximum Sum of 3 Non-Overlapping Subarrays VariableLeetCodeGoogle
689

2.5.2 HashMap + Deque

Window
# Problem Type PlatformCompany
42 Sliding Window Median Fixed LeetCodeGoogle,
480 Amazon
43 Find Median from Data Stream VariableLeetCodeAmazon,
295 Google
44 Longest Substring with At Most K Distinct Characters VariableLeetCodeGoogle
340
45 Max Consecutive Ones III VariableLeetCodeAmazon,
1004 Google

2.5.3 Prefix Sum + Deque

# Problem Window Type Platform Company


46 Shortest Subarray with Sum at Least K Fixed LeetCode 862 Google, Facebook
47 Minimum Window Subsequence Variable LeetCode 727 Google
48 Constrained Subsequence Sum Variable LeetCode 1425 Google

2.6 7. Three or More Data Structures Combined


2.6.1 HashMap + Prefix Sum + Deque

Window
# Problem Type PlatformCompany
49 K Empty Slots Fixed LeetCodeGoogle
683
50 Minimum Window Substring VariableLeetCodeAmazon,
76 Facebook
51 Substring with Concatenation of All Words VariableLeetCodeAmazon,
30 Microsoft

3
2.6.2 Advanced Multi-Structure Problems

Window
# Problem Type PlatformCompany
52 Best Time to Buy and Sell Stock with Transaction Fee VariableLeetCodeAmazon
714
53 Minimum Number of K Consecutive Bit Flips Fixed LeetCodeGoogle
995
54 Replace the Substring for Balanced String VariableLeetCodeAmazon
1234

2.7 Learning Progression Path


2.7.1 Level 1: Foundation (Problems 1-8)
Master basic sliding window with simple conditions

2.7.2 Level 2: Single Data Structure (Problems 9-37)


• Prefix Sum mastery (9-16)
• HashMap/HashSet mastery (17-25)

• Deque mastery (26-31)


• Stack mastery (32-37)

2.7.3 Level 3: Two Structure Combinations (Problems 38-48)


Learn to identify when and how to combine structures

2.7.4 Level 4: Complex Multi-Structure (Problems 49-54)


Advanced problems requiring deep integration

2.8 Problem Selection Strategy


Within each category, problems are ordered to build upon each other:
1. Basic concepts first - Simple application of the technique
2. Add constraints - Same technique with additional conditions

3. Generalize - Extend to more general cases


4. Combine contexts - Apply same technique in different problem domains
5. Optimize - Advanced optimizations and edge cases
Bridge between categories - Each new category starts with a problem that connects to concepts
from previous categories, making the transition smooth and intuitive.

You might also like