Sliding Window
Mindmap
Sliding Window
Types
By window size
Fixed window
Variable window
By goal
Find in window
Longest / Max
Shortest / Min
Others
Count subarrays
Less than K
AtMost(K-1)
Exactly K
AtMost(K) - AtMost(K-1)
Return Indices
Data Structures
Frequency
dict
Unique elements
dict
set
Sum / Avg / Product
Prefix sum
Maintain total
Min / Max element
Deque
O(1)
SortedList
O(log n)
Monoqueue
Requirement
Subarray / Substring
contiguous elements
Only positives
sliding window works
With negatives
use prefix sum instead
Input Structure
Array
manipulate subarray
String
manipulate substring
Phases
every problem
Expansion
Rapid
while loop
Single element
Shrinking
Rapid
while loop
Single element
Problem Logic
apply when window is valid
+
−
⟲
⛶
Problem Categories
Sliding Window
Fixed Window
Naïve Sum / Avg
Hashmap
Duplicate
Unique
Anagrams
Count
Math
Swaps
Misc
Heap
Sorting
Bit Manip.
Longest Sub
Consecutive X
1 Pass
>1 Pass
Hashmap
Unique
K Distinct
Misc
Depends on prev
Shortest Sub
Naive
Two Strings
Return Count / Idx
Naïve Sum / Avg
Longest Sub
Depends on prev
At Most K
Less than K
Exactly K
+
−
⟲
⛶