
Problem
Solution
Submissions
Minimum Window Substring
Certification: Advanced Level
Accuracy: 0%
Submissions: 0
Points: 15
Write a C program to find the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such window in s that covers all characters in t, return the empty string "". If there are multiple valid windows, return the one with the smallest length.
Example 1
- Input: s = "ADOBECODEBANC", t = "ABC"
- Output: "BANC"
- Explanation:
- Step 1: The minimum window substring "BANC" includes one 'A', one 'B', and one 'C' from string t.
- Step 2: This is the shortest substring that contains all characters of t.
- Step 3: Therefore, the answer is "BANC".
Example 2
- Input: s = "a", t = "aa"
- Output: ""
- Explanation:
- Step 1: String t requires two 'a' characters.
- Step 2: String s only contains one 'a' character.
- Step 3: Therefore, no valid window exists, return empty string.
Constraints
- 1 ≤ s.length, t.length ≤ 10^5
- s and t consist of uppercase and lowercase English letters
- Time Complexity: O(|s| + |t|)
- Space Complexity: O(|s| + |t|)
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 sliding window technique with two pointers (left and right).
- Maintain frequency count of characters in t using a hash map.
- Expand window by moving right pointer until all characters of t are covered.
- Contract window by moving left pointer while maintaining validity.
- Keep track of minimum window length and starting position.
- Use a counter to track how many unique characters are fully matched.