src.minimum_window_substring¶
Classes
|
- class src.minimum_window_substring.Solution[source][source]¶
- minWindow(s: str, t: str) str[source]¶
Thought process¶
Problem uses some of the usual things, frequency map to store substring
tand the window ofsKey observation, to achieve an \(O(n)\) solutions we observe that we can define the condition of a substring being contained within a window as a single variable
havebeing compared toneed, where both variables are numeric counts representing the specific letters of the substringWe keep track of the window size and window start and end indices
Abstractly the problem uses the general sliding window approach, so the
rpointer iterates through the loop as normal and thelpointer iterates on a conditionDuring the iteration we consider 3 main conditions :
have != need\(\rightarrow\) expand window ,window[c] == subs[c]\(\rightarrow\) incrementhave,while have == need\(\rightarrow\) move thelpointer and check if we found a new smallest substring
Notes¶
time complexity : \(O(n)\)
space complexity : \(O(n)\)