← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026Remote

Summary

Uber coding round, tree problem that looked straightforward but had enough follow-up surface area to trip you up if you weren't careful. Felt okay about my solution but the generalization question at the end was where things got interesting.

Questions Asked (2)

Q1

Given an N-ary tree where each node has an integer value and a list of children, find the root-to-leaf path with the maximum sum and return the node values along that path.

Algorithms & Data Structures
Author's notes

I went with a single DFS pass returning both the best sum and the path at each node, picking the max-sum child at every step and prepending the current value.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use depth-first search (DFS) to traverse the tree while maintaining the current path and its sum. At each leaf, compare the current sum with the maximum found so far and update the best path if needed. Return the best path after the traversal.

Pro tip: Clarify edge cases upfront, such as negative values and single-node trees, and discuss how your solution handles them. Also, mention that you can optimize space by using a single path list and backtracking instead of copying paths at each step.

1. Clarify the problem

Ask about edge cases: Can node values be negative? What if multiple paths have the same maximum sum? Is the tree guaranteed to be non-empty? Confirm the definition of a leaf (node with no children).

2. Choose the algorithm

Select DFS (recursive or iterative) because it naturally explores root-to-leaf paths. Explain that BFS is less suitable because it doesn't easily maintain path sums.

3. Design the recursive function

Define a helper that takes the current node, the current path list, and the current sum. At each node, add its value to the path and sum. If it's a leaf, compare the sum with the global maximum and update the best path if greater.

4. Handle backtracking

After exploring a node's children, remove the node's value from the current path to backtrack. This ensures the path list correctly represents the current root-to-node path.

5. Analyze complexity and edge cases

State that time complexity is O(N) since each node is visited once, and space complexity is O(H) for recursion stack and path storage, where H is the tree height. Discuss how negative values are handled (they are included in sums) and tie-breaking (e.g., first found or any).

Key Points to Mention

  • Use DFS to explore all root-to-leaf paths.
  • Maintain current path and sum, and update global max at leaves.
  • Backtrack by removing the current node from the path after exploring children.
  • Time complexity O(N), space complexity O(H) for recursion and path.
  • Handle negative values correctly by including them in sums.
  • Consider iterative DFS with an explicit stack if recursion depth is a concern.

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

Q2

How would you extend this to find the maximum sum path between any two nodes in the tree, not just root-to-leaf?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where I had to think out loud for a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Reframe the problem as finding the maximum path sum between any two nodes, which can be solved using a post-order DFS that computes the maximum downward path sum from each node and updates a global maximum with the sum of the node's value plus its two best downward paths. Emphasize that this handles negative values and that the path can go through any node, not just the root.

Pro tip: Mention that the same technique can be adapted to return the actual path, not just the sum, by tracking the endpoints during the DFS. Also, note that this is a common Uber interview question that tests understanding of tree DP and edge cases with negative values.

1. Clarify the problem

Confirm that the path can start and end at any nodes, may go upwards and downwards, and that node values can be negative. Ask if the path must contain at least one node.

2. Define recursive function

Define a helper function that returns the maximum sum of a downward path starting at the current node (including the node itself). This function will be used to compute the best path through each node.

3. Compute global maximum

At each node, compute the sum of the node's value plus the maximum downward paths from its left and right children (if positive). Update a global maximum with this sum, as it represents the best path passing through the current node.

4. Handle negative values and base cases

If a child's downward path sum is negative, treat it as 0 (i.e., don't include that branch). For leaf nodes, the downward path sum is just the node's value. Ensure the global maximum is updated even for single-node paths.

5. Analyze complexity and edge cases

State that the time complexity is O(n) and space is O(h) for recursion. Discuss edge cases: all negative values, single node tree, and skewed trees.

Key Points to Mention

  • Post-order traversal to compute downward path sums
  • Global variable to track maximum path sum
  • Handling negative values by ignoring negative contributions
  • Path can go through any node, not necessarily the root
  • Time complexity O(n) and space complexity O(h)
  • Extension to return the actual path by storing endpoints

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