The key thing that trips people up here is that you're solving two problems at once.
Use a post-order DFS that returns the maximum downward path sum from each node, while maintaining a global maximum that considers paths bending through the node (left + node + right). At each node, compute the best single-branch contribution and update the global answer with the best bent path.
Pro tip: Explicitly handle negative values by clamping branch contributions to 0 (i.e., ignore negative subtrees), and mention that this is a classic 'max gain' tree DP pattern often asked at Adobe.
Confirm that a path can start and end at any node, must follow parent-child edges, and cannot revisit nodes. Ask about input size, node value ranges, and whether the tree can be empty or contain negative values.
For each node, define a function that returns the maximum sum of a downward path starting at that node and going into at most one child. This represents the best contribution the node can offer to its parent.
At each node, compute the best downward path through the left child and right child (clamping negative values to 0). The best path that bends at this node is node.val + leftGain + rightGain; update the global maximum with this value.
Return node.val + max(leftGain, rightGain) to the parent, since a path can only continue in one direction upward. This ensures the parent can form a valid path.
State that the algorithm runs in O(n) time and O(h) space (recursion stack). Discuss edge cases: single node, all negative values, skewed trees, and empty tree.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.