Skip to content
Onsite

Minimum Window Substring

HardP1Coding

Given strings s and t, return the shortest substring of s that contains every character of t, counting multiplicity (if t has two As, the window needs at least two As). If no such substring exists, return the empty string "".

If several windows have the minimum length, return the leftmost one.

Example 1

Input
s = "ADOBECODEBANC", t = "ABC"
Output
"BANC"

Example 2

Input
s = "a", t = "a"
Output
"a"

Example 3

Input
s = "a", t = "aa"
Output
""
Why
s has only one a.

Constraints

  • 1 <= s.length, t.length <= 10^5
  • s and t consist of upper-case and lower-case English letters.

Hints

Run checks the 3 visible tests, Submit all 8.