Given the root of a binary tree, return the length of the diameter — the longest path between any two nodes (measured in edges). The path may or may not pass through the root.
root = [1,2,3,4,5]3root = [1,2]1node == null → return 0L = depth(node.left)R = depth(node.right)diameter = max(diameter, L + R)1 + max(L, R) to parentThe diameter path may not pass through the root. By maintaining a global variable updated at every node, we capture the widest path anywhere in the tree. Post-order guarantees both L and R heights are known before computing L+R — children inform parents, not the reverse.