recur
Blog

Patterns, problems,
explained to stick.

Deep dives on the problems people keep forgetting — explanation first, code second, Big-O defended.

FeaturedSliding Window

Minimum Window Substring, without the hand-waving

The "shrink from the left" step is where everyone gets vague. Here's the invariant that makes it obvious — and the two-counter trick that keeps it O(n).

Jul 2, 2026·3 min read
while right < len(s):
    window[s[right]] += 1
    # invariant: window covers t
    while have == need:
        shrink(left)  # ← the whole trick