Minimum Depth of Binary Tree | LeetCode 111 | Coding Interview Tutorial

Sdílet
Vložit
  • čas přidán 26. 07. 2024
  • Minimum Depth of Binary Tree solution: LeetCode 111
    Implement a queue in JavaScript: • Implement a Queue Tuto...
    Code and written explanation: terriblewhiteboard.com/minimu...
    Link to problem: leetcode.com/problems/minimum...
    Buy Me a Coffee: www.buymeacoffee.com/terrible...
    AFFILIATE LINKS
    If you're interested in learning algorithms, these are great resources.
    💻 40% off Tech Interview Pro: techinterviewpro.com/terriblew...
    ⌨️ 20% off CoderPro: coderpro.com/terriblewhiteboard
    💲 All coupons and discounts 💲
    terriblewhiteboard.com/coupon...
    Minimum Depth of Binary Tree | LeetCode 111 | Coding Interview
    #minimumdepthofbinarytreeii #leetcode #algorithms #terriblewhiteboard #codinginterview
    Click the time stamp to jump to different parts of the video.
    00:00 Title
    00:06 Problem readout
    00:37 Whiteboard solution
    06:11 Coding solution
    12:16 Result and outro

Komentáře • 10

  • @TerribleWhiteboard
    @TerribleWhiteboard  Před 4 lety +13

    If there are any videos you'd like me to make or if you have any ideas on how to optimize this solution, let me know!

    • @anitaganani1018
      @anitaganani1018 Před 3 lety +4

      Could you please explain the time and space complexity?

    • @laibamustafa108
      @laibamustafa108 Před 3 lety +2

      invert a binary tree! thanks for these :)

  • @Yanelyshm
    @Yanelyshm Před 2 lety

    so glad I found your channel. And its in Javascript!! thank you

  • @ChandraShekhar-by3cd
    @ChandraShekhar-by3cd Před 3 lety +4

    Thanks a lot for such a great explanation. I really like this approach. I was thinking to go for DFS , but BFS seems to win my heart.

  • @lamtruong3935
    @lamtruong3935 Před 2 lety

    Best BFS explanation so far

  • @joshuak4742
    @joshuak4742 Před 3 lety

    Your videos help so much, thanks for making these series

  • @susandanielkareem
    @susandanielkareem Před 2 lety

    Great solution, thank youyou!. I noticed it shows a runtime of 240ms when I try to run it though, Am I missing something?

  • @shadmanmartinpiyal4057

    // following solution is similar to "Level order travelsal ii"
    var minDepth = function(root) {
    if(!root) return 0;
    if(!root.left && !root.right) return 1;
    let q = [root], depth = 0, isFound = false;
    while(q.length !== 0 && !isFound){
    let nodeCount = q.length;
    while(nodeCount !== 0){
    const current = q.shift();
    if(!current.left && !current.right){
    isFound = true;
    break;
    }
    if(current.left) q.push(current.left);
    if(current.right) q.push(current.right);
    nodeCount--;
    }
    depth++
    }
    return depth;
    }