Thank you for the daily leetcode problems. For beginners like me , its very helpful. You're a godsend.
@FatCowFat Жыл бұрын
thank you for explaining the daily leetcode problems 👍
@arpanbanerjee6224 Жыл бұрын
you make things super easy! following your channel for a long time now....
@shinewbiez Жыл бұрын
Thank you so much for coming back to solve daily problems. These are very helpful! :D
@laumatthew71 Жыл бұрын
Amazing solution and explanation, thank you !
@picnicbros Жыл бұрын
I was able to make it work with 53/54 but stuck for the last test case, and this video literally posted when I decided to seek help. Thank you!
@NeetCodeIO Жыл бұрын
I actually had the same issue as you I'm guessing 😅
@arpanbanerjee6224 Жыл бұрын
@@NeetCodeIO Can you please tell me what was the issue. Or can you tell me the mistake in the code which resulted the last test case to fail
@asmisrivastava39342 ай бұрын
@@arpanbanerjee6224 pass adjacency matrix by refrence and it will work
@phaneendhrachinta7295 Жыл бұрын
Thanks for the Solution, clearly explained. !
@readonlylogin Жыл бұрын
Great explanation! I don't know python. And now I start thinning about learning python because realization is so cool!
@CostaKazistov Жыл бұрын
I did a double take when I saw the # of subscribers. Seemed off by a factor of 100. Now I get it.
@krishnavamsi9326 Жыл бұрын
You are a great teacher bro! you changed my coding skills forever! Thank you very very much!😀
@kapilchoudhary2922 Жыл бұрын
Beautiful explanation!!
@rsKayiira Жыл бұрын
Great solution and explanation. Only thing I wonder if using a visited hashset may have made the solution clearer
@nihalbhandary1626 ай бұрын
wouldnt matter it is a tree, all the nodes that will be visited could only be encountered once. ( you cant arrive at same vertex from 2 different paths in a tree because it would be a cycle).
@TheSmashtenАй бұрын
Can you do the problem "Making A Large Island"?
@xcampus Жыл бұрын
welcome back neetcode.
@Kilvny Жыл бұрын
Thank you so much for your effort it DOES HELP ALOT
@mohamedsalama27437 ай бұрын
this problem is part of the Trees section in your neetcode list where it should be part of Graphs
@timmyfrank34 ай бұрын
agreed
@xcampus Жыл бұрын
please answer this question. if gennady korotkevich is for codeforce, __________________ is for leetcode? a, neetcode b,neetcode c,neetocode
@kenmatsuru3470 Жыл бұрын
truely amazing!
@krateskim4169 Жыл бұрын
Awesom explanation
@shensean1784 Жыл бұрын
It has to be a noncyclic graph (tree).
@nsandeep7574 Жыл бұрын
Good explanation
@NeetCodeIO Жыл бұрын
Glad to help!
@imaadf5124 Жыл бұрын
Will you be posting all new leetcode videos on this channel?
@NeetCodeIO Жыл бұрын
Yes, all future LC videos
@cj-nr5ni Жыл бұрын
Nailed it
@noahgsolomon Жыл бұрын
Feel like this one should’ve been hard rated
@parikshitjuneja Жыл бұрын
C++ Solution for the same code class Solution { public: int minTime(int n, vector& edges, vector& hasApple) { vector adj(n); for (auto edge : edges) { adj[edge[0]].push_back(edge[1]); adj[edge[1]].push_back(edge[0]); } return dfs(0, -1, adj, hasApple); } int dfs(int curr, int parent, vector& adj, vector& hasApple) { int time = 0; for (auto child : adj[curr]) { if (child != parent) { int childTime = dfs(child, curr, adj, hasApple); if (childTime > 0 || hasApple[child]) { time += (childTime + 2); } } } return time; } };
@ojaswiawasthi3645 Жыл бұрын
Hi !! Thank u so much for this solution !! But can u please can u solve this code by dry run. Actually I got stuck at dfs(4,1). I guess it should return 2 but I come across the continue statement ? :(
@josnamohan9522 Жыл бұрын
Can anyone explain why was there a need to check if child == parent?
@josnamohan9522 Жыл бұрын
@NeetCodeIO
@basecase Жыл бұрын
@@josnamohan9522 while creating adjajency list we are adding the same edge twice e.g. adj[0] has 1 and adj[1] also has 0 otherwise there will be an infinite loop.
@josnamohan9522 Жыл бұрын
@@basecase Thanks for the explanation!
@NeetCodeIO Жыл бұрын
Yeah, Harsh answered it. You might think we don't need to add the edge twice, I did too, but the last test case will fail. Reason is that we need to be able to travel in both directions for this graph, even though it's a tree. And that test case has a child node, with two parents.
@aakashgoswami2356 Жыл бұрын
This guy must be protected at any cost.
@englishtechnique4813 Жыл бұрын
why not in java
@baomao1399 ай бұрын
It didn't work using the above code. I think line 17, it doesn't need to add 2 to every childTime. It should be t += childTime. If at least one childTime > 0 then t += 2 (only once )