0% completed
Hello.I'm having issues understanding how in the example 2, node 1 and node 2 ar...
Jan Carlos Dominguez
Mar 4, 2023
Hello.
I'm having issues understanding how in the example 2, node 1 and node 2 are not counted in the diamater. I know it is supposed to be the longest path between two leaf nodes but in the code I don't see how it is reflected.
Thanks in advanced.
1
0
Comments
Jan Carlos Dominguez3 years ago
The root node receive from the left tree a +1 from its left child node (2) and then receives a +7 from its right child node (3) why then, doesn't return 9? Because it adds both sub trees heights + 1, that 1 being the root node itself.
Jan Carlos Dominguez3 years ago
I'm talking about the python solution btw.
Jan Carlos Dominguez3 years ago
I think I get it now, what each node does is return a height, the bigger one. But the addition is done when updating the diameter by adding two heights.
On this page
Problem Statement
Try it yourself