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
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
binary tree
post-order DFS
dynamic programming on trees
path sum
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported