Tutorialspoint
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 such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string "".

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.
Constraints
  • 1 <= s.length, t.length <= 10^5
  • s and t consist of uppercase and lowercase English letters
  • Time Complexity: O(n)
  • Space Complexity: O(k) where k is the size of the character set
StringsKPMGD. E. Shaw
Editorial

Login to view the detailed solution and explanation for this problem.

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.

Please Login to continue
Solve Problems

 
 
 
Output Window

Don't have an account? Register

Solution Hints

  • Use the sliding window technique to find the minimum window
  • Maintain two frequency maps: one for required characters from t and one for current window
  • Use two pointers to expand or contract the window as needed
  • Keep track of how many characters from t are currently matched

Steps to solve by this approach:

 Step 1: Create two dictionaries - one to store the frequency of characters in string t and another for the current window.
 Step 2: Initialize two pointers, left and right, starting at the beginning of string s.
 Step 3: Move the right pointer to expand the window until all characters in t are found in the current window.
 Step 4: Once all required characters are found, move the left pointer to contract the window while maintaining the requirement.
 Step 5: During contraction, update the minimum window length if a smaller valid window is found.
 Step 6: Continue expanding and contracting until the right pointer reaches the end of string s.
 Step 7: Return the minimum window substring found, or an empty string if no valid window exists.

Submitted Code :