Given a string S and a string T, find the minimum window in S which would contain all the characters in T in complexity O (n ).
For example,
S ="ADOBECODEBANC"
T ="ABC"
Minimum window is "BANC" .
Note:
If There is no such window in S, this covers all characters in T, return the empty string "" .
If There is multiple such windows, you is guaranteed that there would always being only one unique minimum window in S.
classSolution { Public: stringMinwindow (stringSstringt) {unordered_map<Char,int>m; for(Charc:t) {M[c]++; } intSL =s.length (); intCounter =t.length (); intStart =0, end =0; intMinstart =0, Minlen =Int_max; while(End <SL) { if(m[s[end]]>0) {counter--; } M[s[end]]--; End++; while(Counter = =0){ if(End-start <Minlen) {Minstart=start; Minlen= end-start; } M[s[start]]++; if(m[s[start++]) >0) {counter++; } } } if(Minlen <Int_max)returns.substr (Minstart,minlen); Else return ""; }};
Minimum Window Substring