Maximum Depth of Binary Tree - 3 Solutions - Leetcode 104 - Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ก.ค. 2024
  • 🚀 neetcode.io/ - A better way to prepare for Coding Interviews
    🐦 Twitter: / neetcode1
    🥷 Discord: / discord
    🐮 Support the channel: / neetcode
    Twitter: / neetcode1
    Discord: / discord
    ⭐ BLIND-75 SPREADSHEET: docs.google.com/spreadsheets/...
    ⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
    💡 CODING SOLUTIONS: • Coding Interview Solut...
    💡 DYNAMIC PROGRAMMING PLAYLIST: • House Robber - Leetco...
    🌲 TREE PLAYLIST: • Invert Binary Tree - D...
    💡 GRAPH PLAYLIST: • Course Schedule - Grap...
    💡 BACKTRACKING PLAYLIST: • Word Search - Backtrac...
    💡 LINKED LIST PLAYLIST: • Reverse Linked List - ...
    Problem Link: neetcode.io/problems/depth-of...
    0:00 - Read the problem
    1:28 - Recursive DFS
    5:30 - BFS Solution
    10:43 - Iterative DFS
    leetcode 104
    This question was identified as an interview question from here: github.com/xizhengszhang/Leet...
    #binary #tree #python
    Disclosure: Some of the links above may be affiliate links, from which I may earn a small commission.
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 122

  • @NeetCode
    @NeetCode  3 ปีที่แล้ว +36

    🚀 neetcode.io/ - I created a FREE site to make interview prep a lot easier, hope it helps! ❤

  • @534A53
    @534A53 2 ปีที่แล้ว +66

    this was really good, thanks foe showing us the different ways to solve the same problem because its like learning more than one thing at the same time (BFS, DFS, recursion, binary tree traversal, queues, stacks, etc. all in one video)

  • @kleadfusha8338
    @kleadfusha8338 3 ปีที่แล้ว +92

    Your explanations have always been pretty amazing, but somehow they keep getting better and better!!

    • @NeetCode
      @NeetCode  3 ปีที่แล้ว +8

      Thanks, I appreciate your kind words more than you think! 😃

  • @deewademai
    @deewademai ปีที่แล้ว +33

    The third solution should replace the order of "left" and "right" of the stack.append to become a pre-order tree traversal.

  • @iknoorsingh7454
    @iknoorsingh7454 2 ปีที่แล้ว +17

    Hi Neetcode, Great work, keep it up!
    In iterative dfs, I think you should append the right node first because then it should be preorder traversal. But both will work the same anyway.

  • @dipakkumarrai1442
    @dipakkumarrai1442 2 ปีที่แล้ว +1

    Thank you so much for the diagrams sketch! It became clear now

  • @TharaMesseroux1
    @TharaMesseroux1 2 ปีที่แล้ว +2

    Thank you NeetCode for this series!

  • @knockknockyoo5812
    @knockknockyoo5812 2 ปีที่แล้ว

    I've watched his videos for a while. This is one of the best lectures. Thank you so much.

  • @peanutbutter785
    @peanutbutter785 2 ปีที่แล้ว +1

    Such a clear explanation! Thank you :)

  • @marcoespinoza3327
    @marcoespinoza3327 ปีที่แล้ว +3

    God bless you. I have stumbled on your channel and it has been helping me a lot with your explanations. I like how you did all three ways of doing this to help build that intuition for all of them. Thank you so much for making these videos.

  • @raviyadav2552
    @raviyadav2552 2 ปีที่แล้ว

    thnx for showing the different approaches

  • @syafzal273
    @syafzal273 5 หลายเดือนก่อน

    I had only coded up the recursive way, but good to know about the other 2 ways you described in this video

  • @jasonswift7468
    @jasonswift7468 ปีที่แล้ว +3

    This is an extremely wonderful explanation. Keep up the hard work. Btw, it is the post-order method for drawing the third solution. The code of the third solution is a pre-order method. Anyway, It doesn't matter the result of this question. We can take either of pre-order method or the post-order method.

  • @nilshr2
    @nilshr2 3 ปีที่แล้ว +2

    love you bro for great logical solutions

  • @szu-minyu3415
    @szu-minyu3415 4 หลายเดือนก่อน

    Thank you for the clear explanation! You are wonderful :)

  • @aishwaryaranghar3385
    @aishwaryaranghar3385 2 ปีที่แล้ว

    I loved this. Thanks sooo much.

  • @tanoybhowmick8715
    @tanoybhowmick8715 2 ปีที่แล้ว

    Thanks for the explanation.

  • @QVL75
    @QVL75 ปีที่แล้ว

    Excellent explanation!

  • @kirillzlobin7135
    @kirillzlobin7135 10 หลายเดือนก่อน

    Wooow... almost one line solution ))) You are amazing!!!

  • @user-qw8tz5lj7i
    @user-qw8tz5lj7i 6 หลายเดือนก่อน

    Thank you very much for your videos!

  • @abrarmahi
    @abrarmahi 5 หลายเดือนก่อน

    Great video as always

  • @namoan1216
    @namoan1216 2 ปีที่แล้ว +2

    At first it is confusing for me but then I realized and your ideas are really effective

  • @techtransaction
    @techtransaction ปีที่แล้ว +1

    Your videos are really very informative and helps a lot while solving questions .💙💙

    • @BruhhMoment-ij5uo
      @BruhhMoment-ij5uo ปีที่แล้ว

      Hey, Can you tell me why are the leaf nodes returning 1 ? I think they should return 0 because their height is 0, so the height should be 2 right?

  • @josephavila3539
    @josephavila3539 ปีที่แล้ว

    Hello, thank you so much for your amazing content, I am devouring your insights and its helping me grow while gaining confidence. My question, for DFS and BFS, should it be ROOT in the answers opposed to NODE? Thank you.

  • @avtarchandra2407
    @avtarchandra2407 2 ปีที่แล้ว +2

    5:11 made me laugh @neetcode...."I am showing that I am not able to solve even easy problem"

  • @michaelyao9389
    @michaelyao9389 2 ปีที่แล้ว +9

    Somehow, I feel like the iterative dfs is not so `dfs`, it's till kind of `bfs`.

    • @sirmidor
      @sirmidor ปีที่แล้ว +3

      What makes it DFS is that new nodes to search are appended on the right, which is the same place where nodes are popped from. This means that deeper nodes of depth X + 1, which were found from a previous node at depth X, will always be tried before potential other nodes of depth X.

  • @LongVu-sm8wm
    @LongVu-sm8wm 2 ปีที่แล้ว

    great, this is helpful.

  • @manuchehrqoriev
    @manuchehrqoriev 8 หลายเดือนก่อน

    Thank you so much.

  • @vatsalsharma5791
    @vatsalsharma5791 3 ปีที่แล้ว

    Awesome explanation ❤️
    Can you plz make a video on N Queens problem?

  • @lonecreeperbrine
    @lonecreeperbrine 2 ปีที่แล้ว +3

    IDK if this changes anything and if it doesn't can someone explain why. In the last solution when you added things to the stack you appended node.left and then node.right but for preorder traversal shouldn't have node.right been appended then node.left so when you pop the stack the left node is popped first ?

  • @adventurer2395
    @adventurer2395 ปีที่แล้ว +1

    Excellent diverse approaches! The code explanation of the last one was pretty confusing though.

    • @BruhhMoment-ij5uo
      @BruhhMoment-ij5uo ปีที่แล้ว

      Hey, Can you tell me why are the leaf nodes returning 1 ? I think they should return 0 because their height is 0, so the height of the tree should be 2 right?
      because the no. of edges will be the height right?

  • @OMFGallusernamesgone
    @OMFGallusernamesgone 2 ปีที่แล้ว +4

    for BFS, couldnt we just use your iterative DFS solution, but replace the stack with a queue?

  • @sachitrao771
    @sachitrao771 ปีที่แล้ว

    good work sir

  • @nikhilgoyal007
    @nikhilgoyal007 ปีที่แล้ว

    thanks! right should have been appended before the left yes ?

  • @samlinus836
    @samlinus836 ปีที่แล้ว

    Simply awesome

  • @KarthikChintalaOfficial
    @KarthikChintalaOfficial 9 หลายเดือนก่อน +2

    Hey NeetCode,
    In the Iterative DFS approach, within the while loop, if we append like this
    stack.append(node.left, depth+1);
    stack.append(node.right, depth+1);
    When we pop in the next iteration, then the right child will be popped and their children will be added right (because the right child is added last in the stack). I think the order should be reversed here so that the left children will be popped in the next iteration

    • @ashok2089
      @ashok2089 2 วันที่ผ่านมา

      The results will be the same in either way.

  • @tonyz2203
    @tonyz2203 2 ปีที่แล้ว +3

    for the DFS iterative, why do we need to add the Null Node to the stack? We can do :
    if node.left:
    stack.append([node.left, depth+1])
    if node.right:
    stack.append([node.right, depth+1])

    • @harishankar1368
      @harishankar1368 2 ปีที่แล้ว

      We can also choose to not do that and still the result will be the same.

    • @vishnukumar4531
      @vishnukumar4531 2 ปีที่แล้ว

      additional if-checks as part of the code, that is all!

  • @hemesh5663
    @hemesh5663 2 ปีที่แล้ว +2

    Hey as we are following pre order , the order shd be root, left, right then as stack follow lifo shdnt we insert right first and left, this is small doubt anyway technically we will get same. sorry for asking a lame doubt please excuse me.

  • @theFifthMountain123
    @theFifthMountain123 3 หลายเดือนก่อน

    BFS is useful for Leetcode 111.Minimum Depth of Binary Tree. Once you find the first leaf node, (not cur.left and not cur.right) return 1 + depth

  • @RandomShowerThoughts
    @RandomShowerThoughts ปีที่แล้ว +1

    you might be the best at explaining these types of problems, and the theory behind them, wow

  • @mantrax314
    @mantrax314 7 ชั่วโมงที่ผ่านมา

    Thanks!

  • @amberchen5804
    @amberchen5804 ปีที่แล้ว

    Thank you for the awesome explanation. Where can I find the excel sheet at the beginning of your video? I liked the short solution hint

  • @darrylbrian
    @darrylbrian 2 ปีที่แล้ว

    @neetcode - heads up, the link to this video on your website actually takes you to the comments page instead of the video itself.

  • @avtarchandra2407
    @avtarchandra2407 2 ปีที่แล้ว

    thankyou bro for adding the C++ codes on your website i do use fully your website .....and love you so much from India

    • @NeetCode
      @NeetCode  2 ปีที่แล้ว

      No problem, glad it's helpful!

  • @riturajsingh9744
    @riturajsingh9744 2 ปีที่แล้ว +4

    Can you explain why we used 'self', even when we were in the same function (a reference to recursive solution line#12)

    • @NeetCode
      @NeetCode  2 ปีที่แล้ว +10

      It's required in python, since the function belongs to the object (self)

  • @abh830
    @abh830 5 หลายเดือนก่อน +1

    How do you create these videos like on iPad or on the computer as its difficult to drawing otherwise ?

  • @SARDARIN
    @SARDARIN 2 ปีที่แล้ว +1

    @ 11:25 you said in pre order traversal, we visit left tree first. That's not pre order, In preorder we visit the root node first, then the left and right trees.

  • @grigorypiskunov418
    @grigorypiskunov418 2 หลายเดือนก่อน

    Thank you Sir for your work, hardly appreciate that. I actually have a question about the 2nd implementation. If we user pop instead of popleft or use stack as list of values we have an issue for asymmetric trees. In this case we always have +1 vaules of levels. I have checked it with debugger and I don't understand yet why in case we append to the list it add instead of list to the upper Tree element a new one..

  • @alexandersiewert9133
    @alexandersiewert9133 ปีที่แล้ว

    I’m a bit confused on the DSF on why it would be max(result, depth) wouldn’t depth be good enough?

  • @RC-qr8bn
    @RC-qr8bn 2 ปีที่แล้ว +1

    On the Iterative DFS explanation if its using preorder wouldn't 9 on the left subtree be added first to the stack and then 20? It looks like 20 was added first and then 9.

    • @timswen5280
      @timswen5280 ปีที่แล้ว

      I have the same question

  • @juanmacias5922
    @juanmacias5922 11 หลายเดือนก่อน

    I usually don't like recursion, but it was the simplest one. xD

  • @thefuture5162
    @thefuture5162 2 หลายเดือนก่อน

    0:36 😂 You are very funny brother

  • @Ivan_lulz
    @Ivan_lulz 2 หลายเดือนก่อน

    range(len(q)) bothered me a lot until I looked up that it was only evaluated at the start of the for loop.

  • @suri4Musiq
    @suri4Musiq 2 หลายเดือนก่อน

    Do we really need the for loop inside the iterative bfs algorithm? Esp when this is a binary tree?

  • @user-rd4dl3ln8j
    @user-rd4dl3ln8j 8 หลายเดือนก่อน

    The explanation is very good. Please let me know where I can get this code. Please share the link

  • @director8656
    @director8656 3 ปีที่แล้ว +1

    Do I even have to say anything, good video!

  • @JSarko_
    @JSarko_ ปีที่แล้ว +2

    Looking at the recursive dfs solution, how does traversing through each node return the value of 1 just by calling the function? so for example in the return line at 5:10, how does self.maxDepth(node.left) generate a value to be compared with in the max function? I don't see how it gets incremented with every function call?
    Just like to add the explanation of the algorithm is great, its just from a coding standpoint I don't understand because self.maxDepth(node.left) by itself returns 0

    • @jesalgandhi
      @jesalgandhi ปีที่แล้ว +1

      I am also confused about this, if anyone can provide a clear explanation of how a node generates a return value when recursing that would be very helpful

    • @natnaelberhane3141
      @natnaelberhane3141 ปีที่แล้ว +2

      That's because we're adding 1 for each level. So for example, in the recursion, if the tree is empty, we return 0. That would terminate our code and return 0. But if our tree has at least a root, then the depth becomes 1. so we add that value for each level we encounter. that's why the recursive code is return 1 + max(maxDepth(root.left), maxDepth(root.right). So this means, as we go deeper into the tree, we keep adding 1 for each root or level. But once we reach the leaf nodes, the root.left and root.right of the leaf node would return 0.
      For example, if we have a tree with 3 levels,
      a
      b c
      d e
      our function call would be 1 + max(maxDepth(b), maxDepth(c)).
      maxDepth(b) would be 1 + maxDepth(d)
      maxDepth of d would be 1 + max(maxDepth(d.left, d.right))
      both d.left and d.right are none (we hit our base case). Therefore they both return 0.
      This means maxDepth(d) would be 1 + 0
      maxDepth(b) == 1 + maxDepth(d) which is 1 + 1
      maxDepth(a) would be 1 + maxDepth(b) which is 1 + 1 + 1
      So the function will finally return 3.
      Btw since the tree is symmetrical, I only took the a->b->d part of the tree for this explanation.

  • @suri4Musiq
    @suri4Musiq 18 วันที่ผ่านมา

    10:53 Isn't the recurisve DFS a post-order traversal? We first do left, then right and then the current node right? Atleast that's how your code looked in the first solution

  • @thelonerat9557
    @thelonerat9557 ปีที่แล้ว

    5:07 I died

  • @RC-qr8bn
    @RC-qr8bn 2 ปีที่แล้ว +1

    Do you think if I solved this question in a real interview with just recursive DFS would that be enough or should I also learn the iterative way to solve it too just in case.

    • @legatusmaximus6275
      @legatusmaximus6275 2 ปีที่แล้ว +2

      Know iterative and recursive solution

    • @RC-qr8bn
      @RC-qr8bn 2 ปีที่แล้ว

      @@legatusmaximus6275 Thanks

  • @taran7649
    @taran7649 2 ปีที่แล้ว

    The BFS and DFS are both iterative right

  • @khangton4382
    @khangton4382 2 ปีที่แล้ว

    For this particular problem using DFS, why did we opt to use the max keyword? I don't understand the reasoning behind this.

    • @sf-spark129
      @sf-spark129 2 ปีที่แล้ว +1

      It is always better to actually write down the recursive calls' results step by step. Then, you will see why you need max() in the return statement. It took me about 10 problems of Binary Tree until I see that naturally.
      To answer your question, DFS goes deeper and deeper(lower and lower) of the tree recursively until it reaches a leaf node(base case: root = None). From there, it starts building up like climbing up a tree. Let's say you have climbed a good amount on the left side of the tree and also a good amount on the right side. You really can't tell which side you climbed more. Then, max(left, right) will give you the higher side's height(depth) instantly. When you go one step higher, which (let's assume) is the root, then you will get the maximum height(depth) of the tree by 1 + max(left, right).
      Code I use to understand below:
      def maxDepth_DFS(self, root: Optional[TreeNode]) -> int:
      if not root: return 0
      leftNode = self.maxDepth(root.left)
      rightNode = self.maxDepth(root.right)
      return max(leftNode, rightNode) + 1

  • @dipakkumarrai1442
    @dipakkumarrai1442 2 ปีที่แล้ว

    Is there an equivalent Java version of implementing Max Depth of a tree using DFS/stack?

    • @runeyman
      @runeyman 2 ปีที่แล้ว

      public int maxDepth(TreeNode root) {
      Stack stack = new Stack();
      stack.add(new Pair(root, 1));
      int depth = 0;
      while(!stack.isEmpty()){
      Pair temp = stack.pop();
      if(temp.treeNode != null){
      depth = Math.max(temp.integer,depth);
      stack.add(new Pair(temp.treeNode.left, temp.integer + 1));
      stack.add(new Pair(temp.treeNode.right, temp.integer + 1));
      }
      }
      return depth;
      }
      public class Pair{
      TreeNode treeNode;
      int integer;
      public Pair(TreeNode treeNode, int integer){
      this.treeNode = treeNode;
      this.integer = integer;
      }
      }

  • @alexkim8965
    @alexkim8965 ปีที่แล้ว +1

    Why is the last solution DFS Preorder? Shouldn't it be considered as Level Order (BFS)? It goes through nodes by each level (visit/process siblings first) before visiting its child.
    I understand people normally say Queue is BFS and Stack is DFS, but I don't understand this concept. They both look BFS to me whether they use queue or stack, because you visit the nodes from top to bottom, visit/process siblings first before visiting/processing its own child.
    It's a question I had for some time, hope someone can answer 😛

    • @gaochen1328
      @gaochen1328 ปีที่แล้ว

      I am thinking the same! Thank you for asking it and hope to see the answer from the author too!

    • @PrecisionWrittens
      @PrecisionWrittens 11 หลายเดือนก่อน

      That is only because the example tree doesn’t have much of a left side so the traversal gives the illusion of being BFS. However, say node 9 had children 4 and 8. Then we’d visit both 4 and 8 before 20 instead of going right from node 9 to 20. So it’s really just a crappy tree to use as an example bc it doesn’t differentiate BFS and DFS

  • @indhumathi5846
    @indhumathi5846 ปีที่แล้ว

    understood

  • @Sheik1388
    @Sheik1388 ปีที่แล้ว +1

    Can anyone please explain the syntax? I'm very new to OOP with Python, and I don't understand how we actually get the entire list of nodes (for instance "Input: root = [3,9,20,null,null,15,7]") through the treeNode class object which is not even a list...".

    • @oliverheber599
      @oliverheber599 ปีที่แล้ว +2

      Its misleading, root is actually just 3 in that example, they shouldn't call the list root, the list is the entire tree, but only the root (3, with it's left and right (9,20) filled ) will be passed into the maxDepth function

  • @user-zr3hg2zf8e
    @user-zr3hg2zf8e หลายเดือนก่อน

    In a binary tree, the node value on the right should always be greater than the node values on its left, and also the parent node. Does this make the example given by leetcode wrong?

  • @priceton_braswell
    @priceton_braswell 2 ปีที่แล้ว +1

    hate to sound stupid but confused on this one. ive been understanding recursion pretty well but this problem says the input is a root node, but it looks like the input isn't just one node but multiple items in an array. so is the whole array being input as root or just the first one. if its the whole array. would if not root always be true and always return 0. please hellp

    • @staceyonuora5329
      @staceyonuora5329 2 ปีที่แล้ว +1

      The input is the root node but the root node is an object of the class Tree node (the class is defined in comments in the video above the solution class ) which has 3 properties the value, the left node and the right node. You can access all the nodes of the tree just from the root node.
      I hope I was able to help

  • @jugsma6676
    @jugsma6676 3 หลายเดือนก่อน

    Another variant is:
    def solution(root):
    cache = {}
    return helper(root, cache, 1)
    def helper(root, cache, level):
    if not root:
    return True
    cache[level] = root.val # [root.val]
    helper(root.left, cache, level+1)
    helper(root.right, cache, level+1)
    return max(cache.keys())

  • @sergii.golota
    @sergii.golota 2 ปีที่แล้ว +1

    I'm wondering how to transform list to a tree object?
    Is there a python code to do that?

    • @YT.Nikolay
      @YT.Nikolay ปีที่แล้ว

      check out this problem -> leetcode.com/problems/convert-sorted-array-to-binary-search-tree/

  • @hwang1607
    @hwang1607 11 หลายเดือนก่อน

    you are smart

  • @dipanshusingh
    @dipanshusingh ปีที่แล้ว

  • @verayan2019
    @verayan2019 ปีที่แล้ว

    could anyone explain why res = [0] instead of res = 0?

  • @gottuparthiharichandana3381
    @gottuparthiharichandana3381 ปีที่แล้ว

    isn't the maximum depth same as the height of the tree?

  • @fakeasfluff6842
    @fakeasfluff6842 2 ปีที่แล้ว

    A stack in python can hold 2 elements?

    • @milktea2755
      @milktea2755 2 ปีที่แล้ว +1

      I believe the stack in Python is simply a list, and a list can hold individual elements, as well as tuples that hold two elements. This stack just holds a tuple of [node, depth] per node!

  • @abhijitpai6085
    @abhijitpai6085 ปีที่แล้ว

    I lost it at 00:35

  • @choliu1918
    @choliu1918 2 ปีที่แล้ว

    For some reason your BFS solition won’t pass this case on Leetcode today. [3,9,20,null,null,15,7]

    • @MahdiHijazi
      @MahdiHijazi 2 ปีที่แล้ว +1

      The solution has a mistake, level should start from zero

  • @Thejohnster1012
    @Thejohnster1012 ปีที่แล้ว

    final bit of code doesn't match up to drawing as it actually pops the right node first? correct me if wrong

    • @dumbfailurekms
      @dumbfailurekms ปีที่แล้ว

      you are correct. both work, but swap the order of how its pushed to stack to get pre order (NLR)
      This is technically an alternative pre order of NRL

  • @rajivsarkar277
    @rajivsarkar277 3 ปีที่แล้ว +2

    Hi @NeetCode i am unable to grab the recursive and backtracking concept clearly.I have gone through all the videos but still unable to think about a solution using recusrsion and backtrack. will be of great help if u can guide me on the same

  • @mjr6999
    @mjr6999 2 ปีที่แล้ว

    Iterative Depfasajsdkdnf lol😂😂🙏🏻

  • @sf-spark129
    @sf-spark129 2 ปีที่แล้ว

    For the BSF approach, you don't need base case if you code like this:
    Instead of using "if not root: return 0",
    q = deque([root]) if root else None
    will do just fine.
    This is more NeetCode-ish style of code I figured. Yes, you like to keep your code succinct although that can be sometimes difficult to follow. :)
    Code below:
    def maxDepth_BFS(self, root) -> int:
    q = deque([root]) if root else None
    level = 0
    while q:
    for i in q:
    node = q.pop()
    if node.left:
    q.appendleft(node.left)
    if node.right:
    q.appendleft(node.right)
    level += 1
    return level

  • @jonaskhanwald566
    @jonaskhanwald566 3 ปีที่แล้ว +3

    lol. Breadth first search and depth first search are literally tongue twisters. Better say bfs and dfs.

    • @day35ofdebuggingthesamelin56
      @day35ofdebuggingthesamelin56 2 ปีที่แล้ว +6

      what do you mean? It's just depfarstsaerch and breithfasbtshsearsch.

    • @sf-spark129
      @sf-spark129 2 ปีที่แล้ว

      don't forget 'f' in between like me...😂 imagine saying BS in the intervew

  • @amitjoshi7309
    @amitjoshi7309 3 หลายเดือนก่อน

    I am not good with Recursion and tree thats why I cant even solve the simplest one liner solution...............

  • @abh830
    @abh830 5 หลายเดือนก่อน

    create

  • @arnoldwolfstein
    @arnoldwolfstein 4 หลายเดือนก่อน

    in python we don't use camel case. it's snake case.

    • @arnoldwolfstein
      @arnoldwolfstein 4 หลายเดือนก่อน

      for i range(len(q)). oh my

    • @arnoldwolfstein
      @arnoldwolfstein 4 หลายเดือนก่อน

      buy thanks for the content

  • @jmbrjmbr2397
    @jmbrjmbr2397 3 หลายเดือนก่อน

    I have a crush on you Neet..

  • @kedarnadh
    @kedarnadh 3 ปีที่แล้ว +4

    How stack bottom becomes stack top in 3rd approach. pls explain

    • @ua9091
      @ua9091 3 ปีที่แล้ว +3

      Generally stack should start from bottom, but while explaining he started putting items at the top (like a table) which is actually the bottom of the stack.

  • @vs3.14
    @vs3.14 10 หลายเดือนก่อน

    I did catch the node --> root. But ... here's what my aMaZiNg code resulted in -
    AttributeError: 'Solution' object has no attribute 'maxDeapth'. Did you mean: 'maxDepth'?
    **cries in the corner**

  • @Dobby_zuul
    @Dobby_zuul 23 วันที่ผ่านมา +1

    fyi, depth does NOT include the root (height of a tree does), the LeetCode description is wrong, root node is always at max depth 0.

  • @ajayvishwanath1052
    @ajayvishwanath1052 2 ปีที่แล้ว

    Thanks!

    • @NeetCode
      @NeetCode  2 ปีที่แล้ว

      Thank you so much Ajay!!