Minimum Window Substring
Problem statement
Given non-empty strings s and t, return the shortest contiguous substring of s that contains every character of t, including duplicate occurrences.
If no window exists, return the empty string. If several shortest windows exist, return the one with the smallest starting index.
Function
minWindow(s: String, t: String) → StringExamples
Example 1
s = "ADOBECODEBANC"t = "ABC"return = "BANC"BANC is the shortest window containing A, B, and C.
Example 2
s = "a"t = "a"return = "a"The whole one-character string is the answer.
Example 3
s = "a"t = "aa"return = ""The source does not contain enough copies of a.
Constraints
1 ≤ s.length, t.length ≤ 100000.sandtcontain printable ASCII characters.- The total input length fits in memory.
Source note: Interview prompt excerpt preserved as source evidence.