Literally, your explaination is very good. You slolved the complex problem using the simple concept and standard in greedy approach.This make me eassyly to get the idea to solve this.Thank you, teacher!
@@techdose4u class Solution { public: long long dfs(long long node, vector adj, vector& vals, int k, long long & counter, long long parent) { long long sum = vals[node]; for (auto negh : adj[node]) { if (negh != parent) { sum += dfs(negh, adj, vals, k, counter, node); } } sum%=k; if(sum==0) counter++; return sum; } int maxKDivisibleComponents(int n, vector& edges, vector& vals, int k) { long long counter = 0; vector adj(n); for (auto it : edges) { int firstNode = it[0]; int SecondNode = it[1]; adj[firstNode].push_back(SecondNode); adj[SecondNode].push_back(firstNode); } dfs(0, adj, vals, k, counter, -1); return counter; } };
Sir please explain the illustration you draw and the code side by side because many times what happens is beginners like me can't associate the two So it would be really helpful if you tell us which line of code corresponds to which illustration 🙂
You are a great teacher, one of the best i have seen.
thanks for your appreciation
Yes sir, your teaching is just awesome, i have got new enthusiasm for the DSA and i hope i will surely reach my dream destination by following you..
If DSA is the path to your destination then I guarantee you will be posting your success story with me in future here :)
@techdose4u waiting for that day and working for that day from my heart sir .....
I am also your linkedin connection i hope you recognised me....
definitely let me know if I can help you :)
today i participated in biweekly LC contest and was able to solve 1 question :)
great :)
you will improve slowly.
keep up your good work
@@techdose4u sure sir :)
Thanks sir for this consistency 🙏
Consistency is the key 🔑:)
Literally, your explaination is very good. You slolved the complex problem using the simple concept and standard in greedy approach.This make me eassyly to get the idea to solve this.Thank you, teacher!
welcome :)
Consistency🔥
:)
Great Explanation .
Thanks for ur Effort 😎😎.
welcome :)
Ty sir :)
Welcome :)
@techdose sir, i am getting tle for the above code? what to do?
Check if you are passing values by reference or not
Please check your recursion break condition & reference pass as mentioned :)
In java code we can use a static variable and init with 0 on every call, this avoids using an array to store count.
same can be done in c++ using static :)
@techdose4u yes sir 😊
In the dfs function , where does the recursion end and start going back ?
recursion starts with exploring all adjancent edges and ends when loop ends after exploration is done
Thank you sir. How to think about the solution like you sir? I feel stuck on seeing this problem.
Practice the key :)
@@techdose4ufor this question what relevant topics should be practiced sir?
can you also start solving leetcode contest questions. It would really help all of us
if i am passing the adj vector by valyue then it is showing me time limit exceed why??
I had mentioned in the video about integer overflow.
The return type of dfs needs to be set to 64-bit integer. Ex. Long Long dfs()
@@techdose4u fir bhi tle aa rha hai, sir ji
@@techdose4u class Solution {
public:
long long dfs(long long node, vector adj, vector& vals, int k,
long long & counter, long long parent) {
long long sum = vals[node];
for (auto negh : adj[node]) {
if (negh != parent) {
sum += dfs(negh, adj, vals, k, counter, node);
}
}
sum%=k;
if(sum==0) counter++;
return sum;
}
int maxKDivisibleComponents(int n, vector& edges,
vector& vals, int k) {
long long counter = 0;
vector adj(n);
for (auto it : edges) {
int firstNode = it[0];
int SecondNode = it[1];
adj[firstNode].push_back(SecondNode);
adj[SecondNode].push_back(firstNode);
}
dfs(0, adj, vals, k, counter, -1);
return counter;
}
};
@@techdose4u this code is giving tle, what to do??
@@techdose4u means if iam passing vector as values then it requires stack space but in case of passing by reference it does not require stack space??
Sir please explain the illustration you draw and the code side by side
because many times what happens is beginners like me can't associate the two
So it would be really helpful if you tell us which line of code corresponds to which illustration 🙂
Many people might find it too boring hence avoiding that to manage within limited time :)
ab lagta hai agle week tak trees and bfs ke upar hi question ayga
😂
sir aap robot ho kya explanation tora expressive bana skte ho kya
If I make expressive then my sound quality will reduce.
Good mic is costly hence just managing for my resources at hand :)
@techdose4u okay sir you are doing great work and it was just a feedback 😁😁
Yea I too realised that but waiting for collecting some amount for it then will change mic:)