Minimum Window Substring

Sliding Window, problem 6 of 7

Minimum Window Substring

Hard

LC #76

stringhash mapvariable windowcounting

Not attempted yet

Given strings s and t, return the shortest substring of s that contains every character of t, including duplicates (if t has two "a"s, the window needs at least two).

Return "" if no such substring exists. The tests are built so the shortest answer is unique.

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: ""
s has only one "a".

Constraints

  • 1 ≤ len(s), len(t) ≤ 10^5
  • Upper- and lowercase English letters.

Python

Loading draft…

Test results

9 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 6 hidden

Run examples, then submit all tests.