Binary tree diameter and max path sum
You are given a binary tree and need to find the diameter length of the tree. The diameter is defined as the length of the longest path between any two nodes in the tree. This path can pass through or bypass the root node.
Consider the binary tree shown below:
10 / \ 7 8 / \ 4 5
The diameter length is 3, which corresponds to the path [4,7,10,8] or [5,7,10,8].
Another example:
3 \ 9 \ 15 / \ 20 7
The diameter length here is 4, with the longest path being [20,15,9,3] or [7,15,9,3].