The key thing that trips people up is that a path can't branch, so you can't return a forked value upward.
Use a post-order DFS that returns the maximum downward path sum from each node, while updating a global maximum with the best path sum through that node (left + node + right). Handle negative values by allowing paths to start/end anywhere and considering single-node paths.
Pro tip: Explicitly discuss how you handle negative values: if a child's downward sum is negative, treat it as 0 to avoid reducing the total. Also, mention that the global maximum must be updated at every node, not just the root.
Confirm that a path can start and end at any nodes, may go through the root or not, and can consist of a single node. Ask if the tree can be empty or have only negative values.
Design a DFS that returns the maximum sum of a downward path starting at the current node (including the node itself). This path can go to at most one child.
At each node, compute the maximum path sum that passes through the node and goes into both left and right subtrees: node.val + max(0, left) + max(0, right). Update a global maximum with this value.
Return node.val + max(0, left, right) to the parent, since a path cannot split at the parent. Use max(0, ...) to ignore negative contributions.
State that the time complexity is O(n) and space is O(h) for recursion stack. Discuss edge cases: all negative nodes, single node, skewed tree.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.