Is there any way to contact you for query in some other questions (not from your videos) ? For now, I am mentioning the question here , but it would be great if you create some discussion space. Question : Given a tree undirected with n nodes (node i has value v[i]), we define an edge "e" to be good if after removing "e" both subtrees formed have frequency of all values in that subtree
Can you help understand which part was difficult, maybe I can simplify? Regarding code - I intentionally didn't provide code for initial versions so that you can try our yourself. I am always happy to help find the bugs (or point in the right direction). If you don't write code, there is very less value in upsolving because unless you write code you will not know the finer details involved.
Bro, i don't know why you stopped posting videos, if possible kindly resume it, you don't have any idea how much these videos help for people like me, the way you explained step-by-step and 5 methods(my god) is the type of explanation even striver didn't gave in many videos It's a request bhai, if possible please continue to post contest questions
Hi mohan, could you please tell me whats wrong in the below code? it passed 749 / 757 cases. The 750th inputs are soo large that I can't do try run to figure out what's wrong. class Solution { public long validSubstringCount(String word1, String word2) { int n = word1.length(); HashMap w2Map = new HashMap(); HashMap w1Map = new HashMap(); for(char ch : word2.toCharArray()){ w2Map.put(ch,w2Map.getOrDefault(ch,0)+1); } long ans = 0; int cnt = 0; int i = 0; int j = 0; while(j < n){ char ch = word1.charAt(j); w1Map.put(ch,w1Map.getOrDefault(ch,0)+1); if(w2Map.containsKey(ch) && w1Map.get(ch) == w2Map.get(ch)){ cnt++; } while(cnt == w2Map.size()){ ans += n-j; char ithCh = word1.charAt(i); w1Map.put(ithCh,w1Map.get(ithCh)-1); if(w2Map.containsKey(ithCh) && w1Map.get(ithCh) < w2Map.get(ithCh)){ cnt--; } if(w1Map.get(ithCh) == 0){ w1Map.remove(ithCh); } i++; } j++; } return ans; } }
Nice explanation! I like the way you optimize the code gradually from brute-force code.
Very easy to understand code structure for c&d 🔥
thnxxx the way u optimize is really awesome, no one do that.
Is there any way to contact you for query in some other questions (not from your videos) ?
For now, I am mentioning the question here , but it would be great if you create some discussion space.
Question : Given a tree undirected with n nodes (node i has value v[i]), we define an edge "e" to be good if after removing "e" both subtrees formed have frequency of all values in that subtree
now a days, weekly contests are easy. but biweekly are very tough. pls make videos of bi weekly regularly
Difficult to understand completely. Atleast you have to provide the full code of all methods from bruteforce to optimizations.
Can you help understand which part was difficult, maybe I can simplify?
Regarding code - I intentionally didn't provide code for initial versions so that you can try our yourself. I am always happy to help find the bugs (or point in the right direction).
If you don't write code, there is very less value in upsolving because unless you write code you will not know the finer details involved.
Bro, i don't know why you stopped posting videos, if possible kindly resume it, you don't have any idea how much these videos help for people like me, the way you explained step-by-step and 5 methods(my god) is the type of explanation even striver didn't gave in many videos
It's a request bhai, if possible please continue to post contest questions
Hi mohan, could you please tell me whats wrong in the below code? it passed 749 / 757 cases. The 750th inputs are soo large that I can't do try run to figure out what's wrong.
class Solution {
public long validSubstringCount(String word1, String word2) {
int n = word1.length();
HashMap w2Map = new HashMap();
HashMap w1Map = new HashMap();
for(char ch : word2.toCharArray()){
w2Map.put(ch,w2Map.getOrDefault(ch,0)+1);
}
long ans = 0;
int cnt = 0;
int i = 0;
int j = 0;
while(j < n){
char ch = word1.charAt(j);
w1Map.put(ch,w1Map.getOrDefault(ch,0)+1);
if(w2Map.containsKey(ch) && w1Map.get(ch) == w2Map.get(ch)){
cnt++;
}
while(cnt == w2Map.size()){
ans += n-j;
char ithCh = word1.charAt(i);
w1Map.put(ithCh,w1Map.get(ithCh)-1);
if(w2Map.containsKey(ithCh) && w1Map.get(ithCh) < w2Map.get(ithCh)){
cnt--;
}
if(w1Map.get(ithCh) == 0){
w1Map.remove(ithCh);
}
i++;
}
j++;
}
return ans;
}
}