Diameter of Binary Tree - Leetcode 543 - Python

Поделиться
HTML-код
  • Опубликовано: 18 окт 2024

Комментарии • 26

  • @NeetCodeIO
    @NeetCodeIO  2 месяца назад +18

    I've already made a solution for this problem but i thought it could be improved so i rerecorded it.
    If you notice any other problems in the NeetCode 150 (neetcode.io/practice) where the video solution could be improved, please let me know!

    • @floatingpoint7629
      @floatingpoint7629 2 месяца назад +1

      thanks for this, the explanation is much better then the one before
      👍

    • @jeysiva8367
      @jeysiva8367 2 месяца назад

      This explanation is better and clear, Thanks

    • @chronobytes971
      @chronobytes971 Месяц назад +1

      Much better than the previous one! I have understood it at once. Thank you very much

    • @jrose2082
      @jrose2082 Месяц назад

      you’re awesome dude

  • @galkk3
    @galkk3 2 месяца назад +3

    another option that I prefer to use regarding the res variable is to declare it as an array like res = [0]
    and then any time I want to use it it is like this: res[0] = ...

  • @NikithM-vj6pn
    @NikithM-vj6pn 2 месяца назад +6

    I know it is a big thing to ask , but can you make short videos for all the 150 neetcode problems , suggesting the most important parts / techniques / approaches required to solve the problem?
    Huge thanks for your short videos they are helping for quick revision :)

  • @NikithM-vj6pn
    @NikithM-vj6pn 2 месяца назад +3

    could you do reverse linked list nodes in pairs of k?

  • @rryt000
    @rryt000 Месяц назад +3

    can someone explain why the space complexity would be O(h)?

    • @hi-ew2ox
      @hi-ew2ox 24 дня назад +1

      in this case since we're using recursion, the space complexity is based on the maximum number of nodes we're storing in the callstack. this would be equal to the height of the tree, since that is when you have reached the deepest part of the tree from the root.
      in the worst case, if the tree is completely vertical and all the nodes are just stacked on top of each other, the space complexity would be O(N) where N is the number of nodes.
      in the best case, it would be O(h), where h is the height, e.g. as mentioned in the video if the tree was balanced it would be O(logN) since theres a logarithmic relationship between the height and the number of notes (at level h in the balanced tree, there are 2^h nodes)

    • @dusvn1484
      @dusvn1484 22 дня назад

      I have same problem to understand this so I will try to help you on the shortest way.
      The space complexity of recursion dependent on maximum recursive calls at the moment.So as you can see on neet example maximum deep where we can be is the height of tree which value is 3 in video example. Log with base 2 of N where N is equal to 8 is 3.
      So we see the relation of log base 2 of 8 = height of the tree.
      Write me some feedback if this help you :D

  • @zhalzel
    @zhalzel 2 месяца назад

    Great timing this explanation is super clean!

  • @LuisSolorzano-p9u
    @LuisSolorzano-p9u Месяц назад

    Hey thanks for the video! When I was doing this problem I knew that I could use a global variable, but in bigger coding applications global variables should be avoided.
    Do you believe using global variables for interview sessions is okay? Is it too much to ask an interviewer if I'm allowed to use them rather than assume I can use them? Thanks!

  • @benmyths
    @benmyths 2 месяца назад +1

    brother just now i started solving this problem and i see your latest video on it. W timing haha!

  • @mohanedomer9081
    @mohanedomer9081 2 месяца назад

    if you have the time plz do 493. Reverse Pairs . I couldn't understand it at all plz

  • @davitmodebadze9707
    @davitmodebadze9707 2 месяца назад +18

    For a second I thought leetcode posted the daily problem earlier than usual

  • @maanas_sehgal
    @maanas_sehgal 2 месяца назад +3

    Ayy neetcode video at 2:30 AM India❤

  • @Emorinken
    @Emorinken 26 дней назад

    I was wondering why this had just a little over 200 likes, then i realized it was just posted a month ago

  • @mohamedabaza9700
    @mohamedabaza9700 Месяц назад +1

    legend

  • @PDSREACTION
    @PDSREACTION 28 дней назад

    if this is easy then Im mike jackson