Minimum Window Substring
The two pointers and the growing, shrinking window are the easy part of this problem, and you already have them from the earlier lessons. What makes it the hardest standard sliding window question is the bookkeeping: you carry a "need" map and a "have" map, a counter for how many characters are fully covered, and the length of the best window you've seen so far. Get those four pieces straight in your head and the code more or less writes itself.
Example: s = "ADOBECODEBANC", t = "ABC" → "BANC" (length 4)
Nothing genuinely new gets introduced here. Every piece already showed up on its own in an earlier problem, and this is the one where they finally have to work together.
- 1 problem, worked step by step
- 2 diagrams
- about 30 min
Premium lessonData Structures & Algorithms
Keep going with Premium.
All 78 lessons and 103 worked problems in this course, plus what 100 companies ask, pulled from 20,000+ candidate reports.
100 companies. Checked every month.
Unlock the full course$49 a year · less than $1 a week · Cancel anytime