Binary Tree Maximum Path Sum
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
In a binary tree, a **path** is a sequence of nodes where each consecutive pair is joined by an edge, and no node appears more than once. A path has at least one node, does not have to pass through the root, and may turn at most once (going up to some node and then down another branch).
Given the root of a non-empty binary tree, return the largest possible sum of node values along any path. Values can be negative, so the best path may be a single node.
Aim for O(n) time with one post-order traversal.
Examples
Constraints
- 1 <= number of nodes <= 3 * 10^4
- -1000 <= Node.val <= 1000
- The answer fits in a signed 32-bit integer
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.