Minimum Window Substring - 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
Example 1 — Basic Case
$
Input:
s = "ADOBECODEBANC", t = "ABC"
›
Output:
"BANC"
💡 Note:
The minimum window substring "BANC" includes one 'A', one 'B', and one 'C' from t.
Example 2 — No Valid Window
$
Input:
s = "a", t = "aa"
›
Output:
""
💡 Note:
String s only has one 'a', but t requires two 'a's. No valid window exists.
Example 3 — Entire String
$
Input:
s = "a", t = "a"
›
Output:
"a"
💡 Note:
The minimum window is the entire string s, which is "a".
Constraints
- 1 ≤ s.length, t.length ≤ 105
- s and t consist of uppercase and lowercase English letters
Visualization
Tap to expand
Understanding the Visualization
1
Input
Source string s and target string t with required characters
2
Process
Find minimum window in s containing all characters from t
3
Output
Return shortest valid substring or empty string
Key Takeaway
🎯 Key Insight: Use sliding window with hash maps to efficiently track character frequencies while maintaining minimum valid window
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code