Sliding window algorithms.
Move the boundaries, maintain the invariant, then put it into code.
Fixed windows
| Problem | Difficulty | Time complexity | Practice |
|---|---|---|---|
| Maximum Sum of a Size-K Subarray | Easy | O(n) | GFG |
| Maximum Vowels in a Substring | Medium | O(n) | LeetCode |
| First Negative in Every Window | Easy | O(n) | GFG |
| Find All Anagrams in a String | Medium | O(n + m) | LeetCode |
| Permutation in a String | Medium | O(n + m) | LeetCode |
Longest windows
| Problem | Difficulty | Time complexity | Practice |
|---|---|---|---|
| Longest Substring Without Repeats | Medium | O(n) | LeetCode |
| Longest Substring with At Most K Distinct | Medium | O(n) | LeetCode |
| Longest Repeating Character Replacement | Medium | O(n) | LeetCode |
| Max Consecutive Ones III | Medium | O(n) | LeetCode |
Smallest windows
| Problem | Difficulty | Time complexity | Practice |
|---|---|---|---|
| Minimum Size Subarray Sum | Medium | O(n) | LeetCode |
| Minimum Window Substring | Hard | O(n + m) | LeetCode |
Counting windows
| Problem | Difficulty | Time complexity | Practice |
|---|---|---|---|
| Subarrays with Exactly K Distinct | Hard | O(n) | LeetCode |
| Binary Subarrays with Sum | Medium | O(n) | LeetCode |
| Subarray Product Less Than K | Medium | O(n) | LeetCode |
Monotonic deque
| Problem | Difficulty | Time complexity | Practice |
|---|---|---|---|
| Sliding Window Maximum | Hard | O(n) | LeetCode |