I finished the entire sliding window playlist in one day
12 problems, 4 patterns, one gap found. Honest day.
Today felt different. Not because everything went perfectly — it didn’t — but because for the first time this week I finished an entire topic in a single sitting. Two pointers and sliding window, all 12 problems, all 4 patterns. Done.
A week ago I would’ve dragged this across three days. Today I just kept going.
The 4 patterns — locked in
Pattern 1: Constant window
Pattern 2: Variable window — maximize
Pattern 3: Count valid windows
Pattern 4: Minimize the window
Everything today is mapped to one of these. Once you see that, the problems stop feeling random.
Brief on what I solved
Maximum Points From Cards — constant window, inverted thinking
Pick some cards from the left, some from the right. At first glance it doesn’t look like a sliding window problem at all. The insight: fix k cards on the left, then slide — add one from the right, remove one from the left. The window isn’t in the middle, it’s the complement. Key rule: whenever you see “pick a fixed number of elements in any arrangement,” think fixed sliding window.
Longest Substring Without Repeating Characters — wrote my own solution
Solved it without assistance. My solution differed from the video — not better in readability, but I derived it independently. The video’s approach was cleaner: store the last-seen index of each character in a map, jump l directly instead of shrinking one by one. Critical guard: if(mcInd[s[r]] >= l) before updating l, to prevent it going backwards.
Max Consecutive Ones III — O(n) optimization
My first solution was O(2n) — valid but not optimal. The optimization: never shrink the window, only slide it. Move both l and r forward together once the zero count exceeds k. You stop updating the answer until the condition is satisfied again, but the window never gets smaller. Subtle but fast.
Count valid windows — the atMost(k) – atMost(k-1) trick
Binary Subarrays With Sum, Count Nice Subarrays, Subarrays with K Different Integers — all three use the same idea. Counting exactly k is hard. Counting at most k is easy with a sliding window. So: exactly(k) = atMost(k) - atMost(k-1). Once you see this, pattern 3 problems become mechanical.
Minimum Window Substring — expand then shrink
The last pattern and the hardest variety. Expand r until the window satisfies the condition, then shrink l as much as possible while it still holds — that’s your minimum. Track character frequencies with a hash array of size 256. Use a count variable to know when all required characters are covered. The shrinking step is what makes this pattern 4.
Prefix Sum Hashing
Binary Subarrays With Sum exposed something missing. Counting subarrays with a target sum uses prefix sum + hashmap — a pattern I haven’t fully internalized yet. It came up today as a prerequisite I didn’t have. Revising this tomorrow morning before anything else.
Something I noticed about myself
My brain runs well for about 90 minutes, then needs a real break — 30 to 60 minutes. I fought this earlier in the week. Today I worked with it. Took the break when I felt it coming, came back sharper. Fruit Into Baskets clicked right after a pause I almost didn’t take.
Also: I keep second-guessing whether I’m “actually” getting better or just re-solving things I’ve seen before. Today’s honest answer — probably both. But re-solving with understanding is different from re-solving from muscle memory. I can feel the difference.
Sliding window is done.