← Sliding Window

Pattern Recognition Drill

#105 — Minimum Window Substring

Hard Sliding Window

The Problem

Given strings s and t, find the minimum window in s that contains all characters of t.

What approach would you use?

Think about it before scrolling down.

Key Signals

Sliding Window

Expand right to include chars; shrink left while all t chars are covered. Track best window. O(n).

Alt: Hash Map

Two frequency maps (need vs have) with a count of satisfied characters. O(n).

Common Trap

Handle duplicate characters in t correctly — 'have' count must match 'need' count per character.

← #104