Minimum Time to Collect All Apples in a Tree - Leetcode 1443 - Python

preview_player
Показать описание


0:00 - Read the problem
2:30 - Drawing Explanation
7:38 - Coding Explanation

leetcode 1443

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

Thank you for the daily leetcode problems. For beginners like me, its very helpful. You're a godsend.

MP-nyep
Автор

Thank you so much for coming back to solve daily problems. These are very helpful! :D

shinewbiez
Автор

you make things super easy! following your channel for a long time now....

arpanbanerjee
Автор

thank you for explaining the daily leetcode problems 👍

FatCowFat
Автор

Amazing solution and explanation, thank you !

laumatthew
Автор

You are a great teacher bro! you changed my coding skills forever! Thank you very very much!😀

krishnavamsi
Автор

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!

picnicbros
Автор

I recommend still using the standard visited set().

sidazhong
Автор

Great explanation! I don't know python. And now I start thinning about learning python because realization is so cool!

readonlylogin
Автор

Thanks for the Solution, clearly explained. !

phaneendhrachinta
Автор

Thank you so much for your effort it DOES HELP ALOT

Kilvny
Автор

this problem is part of the Trees section in your neetcode list where it should be part of Graphs

mohamedsalama
Автор

I did a double take when I saw the # of subscribers.
Seemed off by a factor of 100.
Now I get it.

CostaKazistov
Автор

Great solution and explanation. Only thing I wonder if using a visited hashset may have made the solution clearer

rsKayiira
Автор

C++ Solution for the same code

class Solution {
public:
int minTime(int n, vector<vector<int>>& edges, vector<bool>& hasApple) {

vector<vector<int>> adj(n);
for (auto edge : edges) {


}

return dfs(0, -1, adj, hasApple);
}

int dfs(int curr, int parent, vector<vector<int>>& adj, vector<bool>& 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;
}
};

parikshitjuneja
Автор

Will you be posting all new leetcode videos on this channel?

imaadf
Автор

Can you do the problem "Making A Large Island"?

TheSmashten
Автор

Feel like this one should’ve been hard rated

noahgsolomon
Автор

It has to be a noncyclic graph (tree).

shensean
Автор

Can anyone explain why was there a need to check if child == parent?

josnamohan