Top 150 InterviewEasy

Minimum Window Substring

Detailed guide and Python implementation for the 'Minimum Window Substring' problem.

Problem Statement

Easy

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.

Constraints
  • m == len(s), n == len(t)
  • 1 <= m, n <= 10^5
  • s and t consist of uppercase and lowercase English letters

Examples

Example 1
Input
s = "ADOBECODEBANC", t = "ABC"
Output
"BANC"
Explanation

The minimum window substring "BANC" (indices 9-12) contains 'A', 'B', and 'C' from t.

Example 2
Input
s = "a", t = "a"
Output
"a"
Explanation

The entire string s is the minimum window.

Example 3
Input
s = "a", t = "aa"
Output
""
Explanation

Both 'a's from t must be included. Since s only has one 'a', return empty string.

Need a Hint?
Consider using Sliding Window-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.