As reported: DoorDash E4 phone screen (2025, passed): LeetCode 124, first with only positive node values, then a follow-up with negative values. Also a coding round of a DoorDash Senior onsite (Toronto, 2025).
This is LeetCode 124 — Binary Tree Maximum Path Sum.
A path in a binary tree is a sequence of nodes where each pair of adjacent nodes is joined by an edge; a node appears at most once, and the path does not need to pass through the root. The path sum is the sum of the node values on the path. Given the root, return the maximum path sum of any non-empty path.
Example 1
root = [1,2,3]
Output: 6
The path 2 → 1 → 3.
Example 2
root = [-10,9,20,null,null,15,7]
Output: 42
The path 15 → 20 → 7.
Constraints: the number of nodes is in [1, 3·10^4]; −1000 ≤ Node.val ≤ 1000.
Follow-ups
- Start with only positive values, then allow negative values.
Code runner format: one JSON value per line: root in LeetCode's level-order format. Implement maxPathSum(root); the harness prints the answer.