Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).
For example,
S =
T =
S =
"ADOBECODEBANC"
T =
"ABC"
Minimum window is
"BANC"
.
Note:
If there is no such window in S that covers all characters in T, return the emtpy string
If there is no such window in S that covers all characters in T, return the emtpy string
""
.
If there are multiple such windows, you are guaranteed that there will always be only one unique minimum window in S.
Use two hashtables to store the required number of chars, and the number of chars we have already found. Check here for more details.
Generally, using array will be faster than hashtable. However, hashtable is more general which can be applied to any char sets.
Use two hashtables to store the required number of chars, and the number of chars we have already found. Check here for more details.
Generally, using array will be faster than hashtable. However, hashtable is more general which can be applied to any char sets.
Comments
Post a Comment