Skip to main content

Minimum Window Substring

HardArrays & Strings

Given two strings s and t, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If no such substring exists, return an empty string "".

Example:

Input: s = "ADOBECODEBANC", t = "ABC"
Output: "BANC"
Explanation: The minimum window containing A, B, and C is "BANC"

Input: s = "a", t = "aa"
Output: ""
Explanation: Both 'a's from t must be included, but s only has one 'a'

Constraints:

  • 1 <= s.length, t.length <= 10^5
  • s and t consist of uppercase and lowercase English letters