Minimum Window Substring
Learn how to solve the 'Minimum Window Substring' problem. This detailed resource details brute force and optimized approaches.
Problem Statement
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.
Write a function minWindow(s: str, t: str) -> str.
- •m == len(s), n == len(t)
- •1 <= m, n <= 10^5
- •s and t consist of uppercase and lowercase English letters
Examples
s = "ADOBECODEBANC", t = "ABC"
"BANC"
The minimum window substring "BANC" (indices 9-12) contains 'A', 'B', and 'C' from t.
s = "a", t = "a"
"a"
The entire string s is the minimum window.
s = "a", t = "aa"
""
Both 'a's from t must be included. Since s only has one 'a', return empty string.
Need a Hint?
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.