15% off all plans & roadmaps Use code
See plansLeetCode 76 · Solution & editorial
Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string "".
Minimum Window Substring is a Sliding Window problem, in the Variable Size (Condition-Based) subpattern. The pattern covers fixed-size, variable-size, and character frequency matching window techniques
Master variable-size sliding window for condition-based problems like longest substring without repeating characters.
The reference solution runs in O(n) time and O(k) space.
Minimum Window Substring has been reported in interviews at Adobe, Airbnb, Amazon, Apple, Bloomberg, ByteDance, Facebook, Goldman Sachs.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Minimum Window Substring is a Sliding Window problem, in the Variable Size (Condition-Based) subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.