76. Minimum Window Substring
Description
Difficulty: Hard
Related Topics: Hash Table, String, Sliding Window
Given two strings s
and t
of lengths m
and n
respectively, return the minimum window substring of s
such that every character in t
(including duplicates) is included in the window. If there is no such substring, return the empty string ""
.
The testcases will be generated such that the answer is unique.
Example 1:
1 | Input: s = "ADOBECODEBANC", t = "ABC" |
Example 2:
1 | Input: s = "a", t = "a" |
Example 3:
1 | Input: s = "a", t = "aa" |
Constraints:
m == s.length
n == t.length
- 1 <= m, n <= 105
s
andt
consist of uppercase and lowercase English letters.
Follow up: Could you find an algorithm that runs in O(m + n)
time?
Hints/Notes
- 2023/08/09
- Sliding window, keep taking new elements while trying to shrink the left boundry
- Use map to record if all required letters are included
- 0x3Fâs solution(checked)
Solution
Language: C++
1 | class Solution { |