Problem · Sliding Window
Minimum Covering Substring
Learn this problemProblem statement
Given strings s and t, return the shortest contiguous substring of s that contains every character of t with at least its required multiplicity.
- Character matching is case-sensitive.
- If several covering substrings have minimum length, return the leftmost one.
- Return the empty string when no covering substring exists.
Function
minCoveringSubstring(s: String, t: String) → StringExamples
Example 1
s = "ADOBECODEBANC"t = "ABC"return = "BANC"BANC is the shortest substring containing A, B, and C.
Example 2
s = "aaabcbcba"t = "aabc"return = "aabc"The substring from index 1 through 4 contains two a characters plus b and c; no shorter window can satisfy four required characters.
Constraints
0 <= s.length, t.length <= 100000.sandtcontain case-sensitive ASCII characters.