LeetCode 543. Diameter of Binary Tree [Solution + Code Explained ]

Поделиться
HTML-код
  • Опубликовано: 8 окт 2024
  • One of the most frequently asked coding interview questions on Arrays in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe etc.
    LeetCode 543. Diameter of Binary Tree
    Question : Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root.
    Example:
    Given a binary tree
    1
    / \
    2 3
    / \
    4 5
    Return 3, which is the length of the path [4,2,1,3] or [5,2,1,3].
    Note: The length of path between two nodes is represented by the number of edges between them.
    Connect with me on LinkedIn at: / jayati-tiwari

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

  • @RajendraSinghRSN
    @RajendraSinghRSN 3 года назад +2

    After going till the end, I got why this video has so many dislikes. Though hats-off for sharing, but it is half baked. Keep the level up.

  • @cakec9
    @cakec9 4 года назад +11

    i am totally confused!!

  • @sukesh0726
    @sukesh0726 4 года назад +2

    Efficient and simple approach...Thank you !!

  • @studyonline3236
    @studyonline3236 2 года назад

    Hi there, it was a nice explanation. Could you also explain the O(n) algo where you calculate height and diameter together?

  • @jewwantcady
    @jewwantcady 3 года назад +1

    Simple and clear. Thank you!

  • @pedrohenriqueleite9382
    @pedrohenriqueleite9382 Год назад

    why have to put +1 when we return max of L,R?

  • @vikramreddy7586
    @vikramreddy7586 4 года назад +10

    She has by-hearted the code wow!!!!!!

    • @varsha9094
      @varsha9094 3 года назад

      hey!why are we returning max(l,r)+1 instead of ans??

    • @siddharthsahu8763
      @siddharthsahu8763 3 года назад

      @@varsha9094 exactly same as my doubt

    • @bekjanomirzak224
      @bekjanomirzak224 3 года назад +1

      @@varsha9094 because we need to include the node itself

  • @himanshusharma-bc5so
    @himanshusharma-bc5so 2 года назад +1

    mugged and pasted !! the funny part is,she works in Facebook..:P

  • @kinglalaboom
    @kinglalaboom 2 года назад

    Thanks!

  • @raj-nq8ke
    @raj-nq8ke 3 года назад +3

    OMG! She is totally wrong. She just crammed the solution without even reading the question. Question clearly states that the diameter is the length of edge and not node but in explanation she says ( l+r+1 ). Delete this video or correct it.

  • @aryanverma7800
    @aryanverma7800 3 года назад +1

    you do a lot of makeup.....just be simple.....it distracts