Problem · String
Minimum Window Substring
Learn this problemProblem statement
Given strings s and t, return the shortest contiguous substring of s that contains every character of t, including duplicate occurrences.
If no such substring exists, return the empty string. The answer is guaranteed to be unique whenever it exists.
Function
minWindow(s: String, t: String) → StringExamples
Example 1
s = "ADOBECODEBANC"t = "ABC"return = "BANC""BANC" contains A, B, and C, and no shorter substring contains all three.
Example 2
s = "a"t = "a"return = "a"The entire source string is the only window and contains the required character.
Example 3
s = "a"t = "aa"return = ""The source string has only one a, so it cannot satisfy the target multiplicity.
Constraints
1 <= s.length, t.length <= 2 * 10^5.sandtcontain printable ASCII characters.- If a valid minimum window exists, it is unique.