Thank you for the daily leetcode problems. For beginners like me , its very helpful. You're a godsend.
@shinewbiez
Жыл бұрын
Thank you so much for coming back to solve daily problems. These are very helpful! :D
@FatCowFat
Жыл бұрын
thank you for explaining the daily leetcode problems 👍
@arpanbanerjee6224
Жыл бұрын
you make things super easy! following your channel for a long time now....
@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
@asmisrivastava3934
3 күн бұрын
@@arpanbanerjee6224 pass adjacency matrix by refrence and it will work
@laumatthew71
Жыл бұрын
Amazing solution and explanation, thank you !
@readonlylogin
Жыл бұрын
Great explanation! I don't know python. And now I start thinning about learning python because realization is so cool!
@phaneendhrachinta7295
Жыл бұрын
Thanks for the Solution, clearly explained. !
@CostaKazistov
Жыл бұрын
I did a double take when I saw the # of subscribers. Seemed off by a factor of 100. Now I get it.
@rsKayiira
Жыл бұрын
Great solution and explanation. Only thing I wonder if using a visited hashset may have made the solution clearer
@nihalbhandary162
3 ай бұрын
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).
@alqam2011
Жыл бұрын
Thank you so much for your effort it DOES HELP ALOT
@krishnavamsi9326
Жыл бұрын
You are a great teacher bro! you changed my coding skills forever! Thank you very very much!😀
@kapilchoudhary2922
Жыл бұрын
Beautiful explanation!!
@xcampus
Жыл бұрын
welcome back neetcode.
@xcampus
Жыл бұрын
please answer this question. if gennady korotkevich is for codeforce, __________________ is for leetcode? a, neetcode b,neetcode c,neetocode
@kenmatsuru3470
Жыл бұрын
truely amazing!
@mohamedsalama2743
5 ай бұрын
this problem is part of the Trees section in your neetcode list where it should be part of Graphs
@timmyfrank3
Ай бұрын
agreed
@krateskim4169
Жыл бұрын
Awesom explanation
@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
@shensean1784
Жыл бұрын
It has to be a noncyclic graph (tree).
@thomas_shelbyyt1349
Жыл бұрын
Big Fan of your work bro
@NeetCodeIO
Жыл бұрын
Thank you 🙏
@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 ? :(
@noahgsolomon
Жыл бұрын
Feel like this one should’ve been hard rated
@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.
@MARTIN-101
5 ай бұрын
0:40 why this is not a binary tree ?
@Kai-cz7wf
20 күн бұрын
There may be chance that there might be no edges between some nodes.. Idk if i am right.. It's just my thoughts.. Correct me if I am wrong
@baomao139
6 ай бұрын
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 )
@aakashgoswami2356
Жыл бұрын
This guy must be protected at any cost.
@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; } };
Пікірлер: 45