← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Uber coding round for a software engineer role. The whole thing was a binary tree problem broken into three parts, and you had to write the node class yourself from scratch before touching any of the logic.

Questions Asked (1)

Q1

Implement a binary tree node class from scratch, without using any library helpers, and then solve three sub-problems: compute the sum of all node values, find the maximum path value among all root-to-leaf paths (where path value is the sum of values along the path), and return the specific leaf node where that maximum path value occurs.

Algorithms & Data Structures
Author's notes

Writing the node class first was a bit of a curveball.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining a simple TreeNode class with value, left, and right attributes. Then implement a single recursive DFS that traverses the tree, computing the sum of all nodes, tracking the maximum root-to-leaf path sum, and recording the leaf node where that maximum occurs. Finally, return the results in the required order.

Pro tip: During the interview, explicitly discuss edge cases such as an empty tree, a single-node tree, and negative values, and clarify how they affect the maximum path sum and leaf identification. Also, mention that you can combine the three computations into one traversal to optimize time.

1. Define the TreeNode class

Create a class with a constructor that initializes the node's value and sets left and right children to None. Ensure it's simple and meets the 'from scratch' requirement.

2. Plan the traversal strategy

Decide on a recursive depth-first search (DFS) that will visit each node exactly once. Explain that you'll pass down the current path sum and update global variables for total sum, max path sum, and the corresponding leaf.

3. Implement the DFS function

Write a recursive function that adds the node's value to the total sum, updates the current path sum, and if the node is a leaf, compares the path sum to the current maximum and updates the max and leaf reference if needed. Then recurse on left and right children.

4. Handle edge cases and return results

After traversal, handle the empty tree case by returning 0, None, or appropriate defaults. Return the total sum, maximum path sum, and the leaf node (or its value) as required.

Key Points to Mention

  • Time and space complexity: O(n) time for visiting each node once, and O(h) space for recursion stack where h is tree height.
  • Handling negative values: ensure the maximum path sum logic correctly compares even when all values are negative.
  • Leaf definition: a node with no children; clarify that the root is a leaf if it has no children.
  • Single traversal efficiency: combining all three computations in one pass avoids multiple traversals.
  • Recursion vs iteration: mention that recursion is natural for trees, but iterative with stack is possible.
  • Returning the leaf node: discuss whether to return the node object or its value, and confirm with the interviewer.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.