Blind 75
15 / 75Free practice

Minimum Window Substring

Hard · Sliding window

Jump to code

Find the shortest substring of s containing every character of t, including repeated copies. Return an empty string if no such window exists; if t is empty, also return an empty string.

Examples

Example 1

s = "ADOBECODEBANC"
t = "ABC"

Output: "BANC"

Example 2

s = "a"
t = "a"

Output: "a"

Constraints

  • 1 <= s.length <= 1000
  • 1 <= t.length <= 1000
  • s and t consist of uppercase and lowercase English letters.
Need a hint?

Track how many required character copies are still missing.

Asked in real interviews

Candidates reported versions of Minimum Window Substring from these company interviews. Some company questions are locked and open with Premium or XP.

Browse all real coding interview questions

Accepted submissions mark this problem complete. Progress stays in this browser.

Run checks 5 examples. Submit checks all 7 cases. A free account runs this problem; no XP needed.
Language
Case 1
Input
[
  "ADOBECODEBANC",
  "ABC"
]
Expected
BANC
Case 2
Input
[
  "a",
  "a"
]
Expected
a
Case 3
Input
[
  "a",
  "aa"
]
Expected
Case 4
Input
[
  "aa",
  "aa"
]
Expected
aa
Case 5
Input
[
  "ab",
  "b"
]
Expected
b

Drafts are saved per language in this browser when storage is available.