Minimum Window Substring
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 "".
The answer is guaranteed to be unique.
Examples
s = "ADOBECODEBANC", t = "ABC""BANC"s = "a", t = "a""a"s = "a", t = "aa"""Constraints
m == s.lengthn == t.length1 <= m, n <= 10^5s and t consist of uppercase and lowercase English letters
š” Hints
Hint 1
Use a frequency map for characters in t.
Hint 2
Expand window right until all characters are covered, then shrink from left to minimize.
Hint 3
Track how many characters are 'satisfied' to know when the window is valid.
Algorithm Complexity
Official asymptotic Big-O runtime and auxiliary memory analysis
Build frequency map of t. Expand window right, counting satisfied chars. When all satisfied, shrink from left to find minimum. Track best result.
Both right and left pointers traverse string s of length m at most once, and initial target frequency map builds in O(n).
Frequency hash maps store counts of characters in target t and current window in s.
š Real-World Use Cases
Finding the shortest text snippet in a document that contains all search query terms ā directly uses min window logic.
ā Premium Challenge
Minimum Window Substring is classified as a premium problem.