LC076 - Minimum Window Substring
Problem
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
Input: s = "ADOBECODEBANC", t = "ABC"
Output: "BANC"
Explanation: The minimum window substring "BANC" includes 'A', 'B', and 'C' from string t.
Solution
Use a hash map to compare number of target characters in current window to target. Progressively decrease window size and shift right after finding a match. This solution is done in linear time and uses extra space.
Last updated