Maximum Incentive Path Sum in a Driver Bonus Tree
Last updated: November 29, 2026
Quick Overview
Each node of a binary tree holds an incentive value that can be negative (a clawback). A path is any sequence of connected nodes with no node repeated, and it need not pass through the root. Return the maximum sum over all non-empty paths.
Uber
November 29, 20260
0
0 solved
Each node of a binary tree holds an incentive value that can be negative (a clawback). A path is any sequence of connected nodes with no node repeated, and it need not pass through the root. Return the maximum sum over all non-empty paths.
An Uber onsite coding question that tests whether you can separate what a recursive call returns to its parent from what it contributes to the global answer. Interviewers watch for correct handling of all-negative trees.
What the Interviewer Expects
- Distinguishes the downward gain returned to the parent from the bent path through a node
- Clamps negative child gains to zero
- Initializes the best answer to negative infinity, not zero
- Handles a tree where every value is negative
- States O(n) time and O(h) space
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the actual node sequence of the best path, not only its sum.
- What if the path must start at the root and end at a leaf?
- How would you make this iterative to avoid recursion depth issues?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: root of a non-empty binary tree with integer values, possibly negative.
- Output: the maximum path sum, where a path can bend at most once (go up then down).
- At least one node must be in th...
High-Level Design
For each node compute gain(node): the best sum of a path that starts at this node and goes down into at most one child. That value is what the parent can extend. While computing it, also consider th...