
Problem
Solution
Submissions
Minimum Window Substring
Certification: Advanced Level
Accuracy: 0%
Submissions: 0
Points: 15
Write a C++ program to solve the Minimum Window Substring problem. Given two strings `s` and `t`, return the minimum window substring of `s` that contains all characters of `t` (including duplicates) in any order. If there is no such substring, return the empty string `""`.
Example 1
- Input: s = "ADOBECODEBANC", t = "ABC"
- Output: "BANC"
- Explanation:
- Step 1: Create a frequency map of characters in string t.
- Step 2: Use a sliding window approach on string s to find windows containing all characters from t.
- Step 3: Keep track of the minimum valid window found.
- Step 4: The minimum window substring "BANC" contains all characters from "ABC".
Example 2
- Input: s = "a", t = "a"
- Output: "a"
- Explanation:
- Step 1: Create a frequency map of characters in string t.
- Step 2: Use a sliding window approach on string s to find windows containing all characters from t.
- Step 3: The entire string "a" already contains all characters from t.
- Step 4: Return "a" as the minimum window substring.
Constraints
- 1 ≤ s.length, t.length ≤ 10^5
- s and t consist of uppercase and lowercase English letters
- The answer is guaranteed to be unique
- Time Complexity: O(n + m) where n is the length of s and m is the length of t
- Space Complexity: O(k) where k is the size of the character set
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Use the sliding window technique with two pointers
- Maintain a frequency map of characters in t
- Expand the right pointer until all required characters are found
- Contract the left pointer to minimize the window size
- Keep track of the minimum valid window found so far