[Approach]Using Recursion - O(n) Time and O(h) Recursive Space
The idea is to use postorder traversal. At each node, calculate left and right path sums, and update a global maximum with (left + node + right). Return the nodeβs value plus the larger side upward. The global maximum at the end gives the answer.
Why this works: Any maximum path in a binary tree must pass through some "highest" node (its root in that path). By considering every node as a possible highest point and updating the maximum with left + node + right, we guarantee that the best path is captured. Returning only one side ensures valid extension toward the parent without breaking the path structure.