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
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.
i am totally confused!!
Efficient and simple approach...Thank you !!
Hi there, it was a nice explanation. Could you also explain the O(n) algo where you calculate height and diameter together?
Simple and clear. Thank you!
why have to put +1 when we return max of L,R?
She has by-hearted the code wow!!!!!!
hey!why are we returning max(l,r)+1 instead of ans??
@@varsha9094 exactly same as my doubt
@@varsha9094 because we need to include the node itself
mugged and pasted !! the funny part is,she works in Facebook..:P
Thanks!
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.
you do a lot of makeup.....just be simple.....it distracts