This is a great explanation. I'm so surprised that nobody wrote any comment about your solution and explanation. Thank you for a clear and easy solution.
That is check and replace the result only if result is not already found (res[0]==-1, this is what we initialized), second is to check if the newly found one is minimum then the existing one(res[0]>r-l+1).
This is a great explanation. I'm so surprised that nobody wrote any comment about your solution and explanation. Thank you for a clear and easy solution.
Thanks for your kind words! Please share it with your friends if you find this video helpful.
The second while loop should be while(l
The most simple and clear solution I found!
This is the best explaination for this problem on youtube. Thank you so much 😊
The best explanation I found for this problem!
I am getting error in if condition it's asking that cannot find variable (invalue()) this is showing me cannot find
Thanks man you saved me lots of time
Great explaination
What is the need of if statement res[0]==-1 || res[0]>r-l+1 in 2nd while loop.I didn't get?
That is check and replace the result only if result is not already found (res[0]==-1, this is what we initialized), second is to check if the newly found one is minimum then the existing one(res[0]>r-l+1).
Very nice explanation! Thanks a lot!
Very great explanation 👌
Best explanation
Great explanation. Thanks.
Simplified approach ! :)
I am doing in normal editor with main method
Well explained and concise! Thank you!
nice explanation bro.
Good explanation. Pronunciation and tone needs a bit of improvement btw.
s = "aa" and t= "aa", this test case is not working
Please check my working solution and please correct me if I am wrong.
class Solution {
public String minWindow(String s, String t) {
if(s ==null || t==null || s.length()==0 || t.length() == 0 || s.length() < t.length())
return "";
Map window = new HashMap();
for(char c:t.toCharArray())
window.put(c,window.getOrDefault(c,0)+1);
Map minWindow = new HashMap();
int l =0;
int r =0;
int expe = 0;
int real = t.length();
int[] output = {-1,0,0};
while(r < s.length()){
char c = s.charAt(r);
minWindow.put(c,minWindow.getOrDefault(c, 0)+1);
if(window.containsKey(c) && minWindow.get(c).intValue() (r-l)+1){
output[0] = (r-l)+1;
output[1] = l;
output[2] = r;
}
char cc = s.charAt(l);
minWindow.put(cc,minWindow.getOrDefault(cc, 0)-1);
if(window.containsKey(cc) && minWindow.get(cc).intValue() < window.get(cc).intValue()){
expe--;
}
l++;
}
r++;
}
return (output[0]==-1?"":s.substring(output[1],output[2]+1));
}
}
Because this solution only works if t only contains unique chars.
The simplest explaination u will find on internet..