Optimal Algorithmic Approach
Post-order DFS: each node returns its height; update global diameter.
Core Invariants & Edge Cases
- At each node compute height of left and right subtrees
- Diameter through this node = leftHeight + rightHeight
- Track global maximum as you recurse