Check Completeness of a Binary Tree - Leetcode 958 - Python

Поділитися
Вставка
  • Опубліковано 12 вер 2024

КОМЕНТАРІ • 23

  • @rithickchowdhury7116
    @rithickchowdhury7116 Рік тому +14

    Key is once you find a null node , you mustn't get any other non null node from the tree..if there is the return false.

  • @tuandino6990
    @tuandino6990 2 місяці тому

    Beautiful solution, I write 1 page long of code for this problem ...

  • @Vancha112
    @Vancha112 Рік тому +1

    Very clear:) even for someone with very little dsa experience, thanks!

  • @shubhamsharma6033
    @shubhamsharma6033 Рік тому

    You make it very easy to understand. So, when I am stuck on a problem. I go to your channel

  • @sergiohernandez72
    @sergiohernandez72 Рік тому

    Still making great videos, keep up the great work. I like that I can pretty much solve it just from your explanation before you even show the code.

  • @victoriatfarrell
    @victoriatfarrell Рік тому

    My solution was similar in principle but a lot longer. Thanks for sharing this, very succinct!

  • @x12624
    @x12624 Рік тому +1

    What does he use for drawing? How do you draw in the same page as the question? Do you use an iPad to draw and write?

    • @DinujayaRajakaruna
      @DinujayaRajakaruna Рік тому

      I think he uses paint, he must have taken a screen grab of the problem and paste it on the canvas

  • @akhma102
    @akhma102 Рік тому

    very needed. thank you!

  • @mohithadiyal6083
    @mohithadiyal6083 Рік тому

    Amazing explanation 👍

  • @krateskim4169
    @krateskim4169 Рік тому

    This is such a great solution

  • @saurabhd7990
    @saurabhd7990 Рік тому

    Thanks for the video

  • @Tim_desu
    @Tim_desu Рік тому

    so brilliant... I just came out with some bad methods and messy code

  • @ambarkansal
    @ambarkansal Рік тому

    dhanyavad ji 🟠⚪🟢

  • @hufsonian
    @hufsonian Рік тому

    that was beautiful

  • @hoyinli7462
    @hoyinli7462 Рік тому

    super smarrt!

  • @akshitaven9060
    @akshitaven9060 Рік тому

    Could someone help me understand why the space complexity not O(log n) which is the height of the three?

    • @mubeenkodvavi6308
      @mubeenkodvavi6308 Рік тому +6

      The space complexity is not O(log n) as BFS traverses the tree level by level, and not store elements by node's path like DFS
      At one time, max queue size (space needed) will be the max width of the tree, that is O(n/2 + 1) indicating last level of complete binary tree, which is simplified to O(n)

  • @dark_sky3177
    @dark_sky3177 Рік тому

    Amazing explanation..._/\_

  • @shubhamraj25
    @shubhamraj25 Рік тому

    C++ implementation
    bool isCompleteTree(TreeNode* root) {
    bool flag = false;
    queue q;
    q.push(root);
    while (!q.empty()) {
    int n = q.size();
    for (int i = 0; i < n; i++) {
    TreeNode* node = q.front();
    q.pop();
    if (!node) {
    flag = true;
    } else {
    if (flag) {
    return false;
    }
    q.push(node->left);
    q.push(node->right);
    }
    }
    }
    return true;
    }

    • @mubeenkodvavi6308
      @mubeenkodvavi6308 Рік тому

      You dont need inner for loop for this use case.

    • @kevinjmathews2964
      @kevinjmathews2964 Рік тому

      @@mubeenkodvavi6308 yeah not required. But for some reason leetcode gives a better runtime with the for loop (at least for python that's the case).

    • @committedeel1751
      @committedeel1751 Рік тому

      @@kevinjmathews2964 leetcode runtime is biased so I wouldn't be too reliant on it - as long as you can explain your solution in great detail with runtime you should be fine