Minimum Window Substring
Find the shortest contiguous substring of s that contains all characters of t including duplicates using an expand-and-shrink sliding window.
01The problem
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 testcases will be generated such that the answer is unique.
| Input | Output | Why |
|---|---|---|
s = "ADOBECODEBANC", t = "ABC" | "BANC" | "BANC" contains 'A', 'B', and 'C' and has length 4 |
s = "a", t = "a" | "a" | Exact single-character match |
s = "a", t = "aa" | "" | s has only one 'a', but t requires two |
s = "bba", t = "ab" | "ba" | Window at the very end |
Constraints: 1 to 100,000 characters, English uppercase and lowercase letters.
Loading the rest of the lesson…