#76

Minimum Window Substring

candidate master · 1505 · lc hard +32 · verified · 47% accepted · 20,041 likes · top 32%

play →

Description

Find the shortest substring of s that contains every character in t including duplicates. Return "" if no such window exists. The answer is guaranteed to be unique.

Example 1:

Input: s = "ADOBECODEBANC", t = "ABC"
Output: "BANC"
Explanation: The minimum window substring "BANC" includes 'A', 'B', and 'C' from string t.

Example 2:

Input: s = "a", t = "a"
Output: "a"
Explanation: The entire string s is the minimum window.

Example 3:

Input: s = "a", t = "aa"
Output: ""
Explanation: Both 'a's from t must be included in the window.
Since the largest window of s only has one 'a', return empty string.

Code

1
2
3