You are given two strings s and t. Return the shortest contiguous substring (window) of s that contains every character of t, including duplicates: if t has a character twice, the window must contain it at least twice. Characters are case-sensitive.
If no such window exists, return the empty string "". If several windows tie for the minimum length, return the one that starts earliest in s. This tie-break makes the answer unique.
Examples
Example 1
Input: s = "ADOBECODEBANC", t = "ABC"
Output: "BANC"
Explanation: "BANC" is the shortest window containing 'A', 'B' and 'C'.
Example 2
Input: s = "a", t = "a"
Output: "a"
Example 3
Input: s = "a", t = "aa"
Output: ""
Explanation: t needs two 'a's but s contains only one.
Constraints
m ==s.length, n ==t.length
1≤m,n≤105
s and t consist of uppercase and lowercase English letters.
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up