2023-12-09 18:42:21 +08:00
< p > Given two strings < code > s< / code > and < code > t< / code > of lengths < code > m< / code > and < code > n< / code > respectively, return < em > the < strong > minimum window< / strong > < / em > < span data-keyword = "substring-nonempty" > < strong > < em > substring< / em > < / strong > < / span > < em > of < / em > < code > s< / code > < em > such that every character in < / em > < code > t< / code > < em > (< strong > including duplicates< / strong > ) is included in the window< / em > . If there is no such substring, return < em > the empty string < / em > < code > " " < / code > .< / p >
2022-03-27 18:35:17 +08:00
< p > The testcases will be generated such that the answer is < strong > unique< / strong > .< / p >
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 1:< / strong > < / p >
2022-03-27 18:35:17 +08:00
< pre >
< strong > Input:< / strong > s = " ADOBECODEBANC" , t = " ABC"
< strong > Output:< / strong > " BANC"
< strong > Explanation:< / strong > The minimum window substring " BANC" includes ' A' , ' B' , and ' C' from string t.
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 2:< / strong > < / p >
2022-03-27 18:35:17 +08:00
< pre >
< strong > Input:< / strong > s = " a" , t = " a"
< strong > Output:< / strong > " a"
< strong > Explanation:< / strong > The entire string s is the minimum window.
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 3:< / strong > < / p >
2022-03-27 18:35:17 +08:00
< pre >
< strong > Input:< / strong > s = " a" , t = " aa"
< strong > Output:< / strong > " "
< strong > Explanation:< / strong > Both ' a' s from t must be included in the window.
Since the largest window of s only has one ' a' , return empty string.
< / pre >
< p > < / p >
< p > < strong > Constraints:< / strong > < / p >
< ul >
< li > < code > m == s.length< / code > < / li >
< li > < code > n == t.length< / code > < / li >
2023-12-09 18:42:21 +08:00
< li > < code > 1 < = m, n < = 10< sup > 5< / sup > < / code > < / li >
2022-03-27 18:35:17 +08:00
< li > < code > s< / code > and < code > t< / code > consist of uppercase and lowercase English letters.< / li >
< / ul >
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong > Follow up:< / strong > Could you find an algorithm that runs in < code > O(m + n)< / code > time?< / p >