Hard
Sliding Window
Minimum Window Substring
Expand to satisfy the requirement, then contract to minimize.
Approach
Count the characters you need. Expand the right edge until the window contains all of them, then contract the left edge as far as possible while still valid, recording the smallest such window. A 'need' counter lets you check validity in O(1) per step.
Time complexity
O(n)
Space complexity
O(alphabet)
Common mistake
Only expanding, never contracting — the minimum window requires shrinking whenever the constraint is still met.
See it run, step by step
Generate an interactive lesson for Minimum Window Substring — trace every variable and watch the algorithm execute until it clicks.
Start a lesson on Minimum Window Substring