Each subpattern solves a specific type of problem. Click on a card to view its template.
Window width is constant — slide by adding right element and removing left.
Expand greedily; shrink only when the window breaks the constraint.
Expand until window satisfies the goal; then shrink as far as possible.
exact(K) = atMost(K) − atMost(K−1). Converts exact-count problems into two window calls.
Track the max or min inside every window in O(1) using a monotonic deque.
Slide a window over one string while checking coverage of a target pattern.
Template for: Fixed Size Window
1int fixedWindow(vector<int>& nums, int k)2{3 // ── Step 1: build first window ──────────────────4 int windowState = 0;5 for (int i = 0; i < k; i++)6 {7 windowState += nums[i];8 }910 // ── Step 2: record answer for first window ───────11 int best = windowState;1213 // ── Step 3: slide window from index k to N-1 ─────14 for (int R = k; R < (int)nums.size(); R++)15 {16 windowState += nums[R]; // add incoming right element17 windowState -= nums[R - k]; // remove outgoing left element1819 // ── Step 4: update answer ──────────────────────20 best = max(best, windowState);21 }2223 return best;24}
LeetCode #
LeetCode #643
LeetCode #1052
LeetCode #1423
LeetCode #995
LeetCode #567
LeetCode #438
LeetCode #1358
LeetCode #3
LeetCode #159
LeetCode #340
LeetCode #904
LeetCode #1004
LeetCode #424
LeetCode #209
LeetCode #76
LeetCode #1658
LeetCode #713
LeetCode #930
LeetCode #1248
LeetCode #992
LeetCode #239
LeetCode #1438
LeetCode #1696
LeetCode #1425