MINIMUM DEPTH OF BINARY TREE | LEETCODE # 111 | PYTHON DFS SOLUTION

  Рет қаралды 7,888

Cracking FAANG

Cracking FAANG

Күн бұрын

Пікірлер: 16
@antoinenijhuis450
@antoinenijhuis450 10 ай бұрын
Thanks for this video, very insightful breakdown of the question.
@leeroymlg4692
@leeroymlg4692 9 ай бұрын
Hello everyone welcome back and let's write some more neetcode today
@crackfaang
@crackfaang 9 ай бұрын
Noooooooo 🙅‍♂️🙅‍♂️
@antoinenijhuis450
@antoinenijhuis450 10 ай бұрын
For a CS Graduate that is not very strong in projects resumé but loves grinding leetcode. Should I focus on projects first before getting into Leetcode 150? Or do you reckon it is useful for me to grind these kind of problems without much programming experience?
@jaredtewodros
@jaredtewodros Жыл бұрын
How can you implement this solution without the global min variable?
@LawAssistantAI
@LawAssistantAI 6 ай бұрын
n this particular scenario, if we find a leaf node, we could technically stop searching further because we already have a minimum depth candidate. This approach is especially useful in the context of finding the minimum depth of a binary tree. Instead of searching all the nodes unnecessarily, we can stop the search early when we find the first leaf node at the current minimum depth. This would prevent us having to continue to traverse, wouldnt it?
@Tallonest
@Tallonest 2 ай бұрын
No, because what if you start at the root and find a leaf node on the left subtree 3 down? If you explore the right subtree next, what if you find it’s 1 down? So you actually need to keep going
@vabhs192003
@vabhs192003 8 ай бұрын
Wouldn't the following test case fail for the empty tree such as [], since the default value is set as float('int') while the value returned should be 0?
@ilhomsadriddinov3627
@ilhomsadriddinov3627 Жыл бұрын
Why didn’t you use bfs approach which is slightly better for average cases. I mean traversing the tree by level.
@crackfaang
@crackfaang Жыл бұрын
In retrospect I should have used BFS because you can theoretically stop early but in the case of an extremely skewed tree, the overall time complexity is the same. We only care about worst case runtime complexity when doing the analysis so both are fine. You could mention the average case thing for some bonus points but either answer works here as they are the same overall time/space complexity
@moezzzz9341
@moezzzz9341 Жыл бұрын
one thing im confused is how you have access to minDepth in your dfs method which is defined in the original method? Is it because you are attaching self to the front of it so both methods have access to that variable?
@versace10
@versace10 Жыл бұрын
hes not calling the method he created a min_depth variable which hes using
@rishikaverma9846
@rishikaverma9846 Жыл бұрын
ValueError: could not convert string to float: 'int' self.min_depth = float('int') Line 11 in minDepth (Solution.py) ret = Solution().minDepth(param_1) Line 38 in _driver (Solution.py) _driver() Line 49 in (Solution.py) the same code shows this error. can you please tell me how to solve it?
@crackfaang
@crackfaang Жыл бұрын
It’s float(‘inf’) not ‘int’. You spelled it wrong 😉
@leetcoderafeeq2641
@leetcoderafeeq2641 2 жыл бұрын
thank you
@sarayarmohammadi3376
@sarayarmohammadi3376 10 ай бұрын
thank you
Миллионер | 3 - серия
36:09
Million Show
Рет қаралды 2 МЛН
They Chose Kindness Over Abuse in Their Team #shorts
00:20
I migliori trucchetti di Fabiosa
Рет қаралды 12 МЛН
Players push long pins through a cardboard box attempting to pop the balloon!
00:31
風船をキャッチしろ!🎈 Balloon catch Challenges
00:57
はじめしゃちょー(hajime)
Рет қаралды 92 МЛН
CLONE GRAPH | LEETCODE # 133 | PYTHON BFS SOLUTION
9:28
Cracking FAANG
Рет қаралды 3,1 М.
A* (A Star) Search Algorithm - Computerphile
14:04
Computerphile
Рет қаралды 1,1 МЛН
Symmetric Tree - Leetcode 101 - Python
6:40
NeetCodeIO
Рет қаралды 39 М.
Diameter of a Binary Tree - Leetcode 543 - Python
15:34
NeetCode
Рет қаралды 237 М.
LOWEST COMMON ANCESTOR OF A BINARY TREE III [PYTHON]
16:38
Cracking FAANG
Рет қаралды 12 М.
LOWEST COMMON ANCESTOR OF A BINARY TREE II | PYTHON | LEETCODE 1644
20:46
How to solve (almost) any binary tree coding problem
4:20
Inside code
Рет қаралды 187 М.
Миллионер | 3 - серия
36:09
Million Show
Рет қаралды 2 МЛН