Sliding Window Pattern Hub
5 problemsBest Time to Buy and Sell Stock
easyTrack `minPrice` seen so far; at each day `p`, candidate profit is `p - minPrice`.
Longest Repeating Character Replacement
mediumA window `[l..r]` is valid iff `windowLength - maxFreq <= k`. Crucial optimization: never shrink `maxFreq` down when advancing `l`, because a strictly longer window requires a strictly larger `maxFreq`!
Longest Substring Without Repeating Characters
mediumStore `{ char: lastIndex }`. When character `c` repeats at `r` and `lastIndex[c] >= l`, jump left pointer directly to `lastIndex[c] + 1` in O(1) instead of creeping `l` step-by-step.
Minimum Window Substring
hardMaintain `have == need` count of distinct required characters from `t`. Expand `r` until `have == need`, then advance `l` aggressively while maintaining `have == need` and updating the smallest slice.
Permutation in String
mediumMaintain a fixed window of size `len(s1)` sliding over `s2`, updating character match count `matches` out of 26 in O(1) per slide instead of comparing two 26-arrays every step.