Back to Practice Dashboard
Top 150 InterviewEasy

Minimum Window Substring

Learn how to solve the 'Minimum Window Substring' problem. This detailed resource details brute force and optimized approaches.

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?
Maintain a sliding window boundary using two pointers. Expand the right boundary, and contract the left boundary if criteria are violated.
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.

Open in Editor