Sliding window
Episode 23 Minimum Window Substring
▶ This video is coming to YouTube soon.
LeetCode 76, Minimum Window Substring, solved on screen. Three examples show what counts: the classic ADOBECODEBANC, a t with a repeated letter, and a t that s can't cover. The brute force checks every substring, O(m² · (m + n)). Then a sliding window with a need counter grows on the right until it covers t, and shrinks from the left while it still does, recording the shortest: O(m + n) time, O(1) space.
What you'll learn
- What Minimum Window Substring asks, through three worked examples
- The brute force: every substring, O(m² · (m + n)) time
- need and missing: knowing in O(1) whether the window covers t
- Grow right until the window covers t, shrink left while it still does
- Why this window's while loop runs while the window is valid
Chapters
- 0:00The problem
- 0:17Examples
- 0:53Brute force, visualized
- 1:34Brute force: the code
- 1:49Brute force, line by line
- 2:38Sliding window: the idea
- 2:58Sliding window, visualized
- 3:55Sliding window: the code
- 4:16Sliding window, line by line
- 5:23Comparing the approaches