← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Uber SWE interview that was basically a binary tree deep dive. They had me implement the node class from scratch first, then build on it across three connected subproblems. Not the hardest thing I've done but writing the class yourself before solving anything adds a layer of pressure.

Questions Asked (4)

Q1

Implement a binary tree node class from scratch without using any library helpers.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

They wanted the full class, not just a struct with two pointers.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements and constraints, then design a clean, generic node class with essential fields and methods. Implement the class from scratch, ensuring proper encapsulation and memory management, and discuss trade-offs like mutability and recursion vs iteration.

Pro tip: Mention that you would make the node class generic to support any data type, and discuss how you'd handle edge cases like null children to demonstrate production-level thinking.

1. Clarify Requirements

Ask about the expected operations (insert, delete, traverse), data types, and whether the tree is binary search tree or just binary tree. Confirm if recursion is acceptable and if memory constraints exist.

2. Design the Node Class

Define fields: value, left child, right child. Consider adding parent pointer if needed. Decide on visibility (public/private) and whether to include methods like isLeaf().

3. Implement Core Methods

Write constructors, getters/setters if necessary, and basic operations like insert, search, and traversal (in-order, pre-order, post-order). Ensure proper null checks.

4. Discuss Trade-offs

Explain choices: recursive vs iterative traversal (stack overflow risk vs code simplicity), mutability of fields, and memory overhead of parent pointers. Mention time/space complexity.

5. Test and Validate

Walk through example insertions and traversals, including edge cases like empty tree, single node, and skewed tree. Verify correctness and discuss potential improvements.

Key Points to Mention

  • Generic type parameter for flexibility (e.g., Node<T>)
  • Proper encapsulation with private fields and public methods
  • Null handling for left and right children
  • Recursive vs iterative traversal trade-offs (stack overflow, performance)
  • Time and space complexity of operations (O(n) for traversal, O(log n) for balanced insert)
  • Memory management considerations (e.g., avoiding memory leaks in languages without GC)

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

Q2

Given a binary tree using your node class, compute the sum of all node values.

Algorithms & Data Structures
Author's notes

Warmup part of a three-part problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the tree structure and constraints, then discuss both recursive and iterative approaches. For the recursive approach, define a function that returns the sum of the current node plus the sums of its left and right subtrees. For the iterative approach, use a stack (DFS) or queue (BFS) to traverse the tree and accumulate the sum.

Pro tip: Mention that recursion depth could be an issue for skewed trees and that an iterative approach avoids stack overflow. Also, note that the problem can be solved in O(n) time and O(h) space for recursion, where h is the tree height.

1. Clarify the problem

Ask about edge cases: empty tree, negative values, and whether the tree is balanced. Confirm the node class definition and that we need to sum all node values.

2. Discuss approaches

Present both recursive and iterative solutions. Explain the recursive approach: sum = node.value + sum(left) + sum(right). For iterative, describe using a stack or queue to traverse and accumulate.

3. Analyze complexity

State that both approaches visit each node once, so time complexity is O(n). Space complexity is O(h) for recursion (due to call stack) and O(n) for iterative in the worst case (e.g., skewed tree).

4. Handle edge cases

Mention handling null root (return 0), negative values (sum can be negative), and large trees (iterative avoids stack overflow).

5. Code and test

Write clean code for the chosen approach, then walk through a small example to verify correctness. Discuss potential optimizations if needed.

Key Points to Mention

  • Recursive solution: base case for null node, return 0; otherwise return node.value + sum(left) + sum(right).
  • Iterative solution: use stack for DFS or queue for BFS, initialize sum to 0, push root, then while stack not empty, pop node, add value, push children.
  • Time complexity: O(n) because each node is visited once.
  • Space complexity: O(h) for recursion (h = height), O(n) for iterative in worst case.
  • Edge cases: empty tree returns 0, negative values handled naturally.
  • Trade-offs: recursion is simpler but may cause stack overflow for deep trees; iterative is more robust but requires explicit data structure.

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

Q3

Find the maximum path value among all root-to-leaf paths, where path value is the sum of node values along the path.

Algorithms & Data Structures
Author's notes

This is where it got interesting.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: confirm that the tree is binary, node values can be negative, and a leaf is a node with no children. Then present a recursive DFS solution that computes the maximum root-to-leaf sum by returning the maximum of the left and right subtree sums plus the current node's value, with a base case for null nodes returning negative infinity.

Pro tip: Mention that you would handle negative values by initializing the maximum to negative infinity and that you'd discuss iterative alternatives (e.g., using a stack) if recursion depth is a concern. This shows you consider edge cases and production constraints.

1. Clarify the problem

Ask about tree type (binary?), leaf definition, and whether node values can be negative. Confirm the expected output (maximum sum).

2. Outline the recursive approach

Explain that for each node, the maximum root-to-leaf sum is the node's value plus the maximum of the sums from its left and right subtrees. Base case: null node returns negative infinity.

3. Walk through an example

Trace the algorithm on a small tree, including negative values, to demonstrate correctness and how the maximum is propagated.

4. Analyze complexity

State that time complexity is O(n) since each node is visited once, and space complexity is O(h) for recursion stack, where h is tree height.

5. Discuss edge cases and alternatives

Mention handling of empty tree, single node, and all negative values. Optionally, describe an iterative DFS using a stack to avoid recursion limits.

Key Points to Mention

  • Recursive DFS with post-order traversal
  • Base case: null node returns negative infinity (or a very small number)
  • Handling negative node values correctly
  • Time complexity O(n) and space complexity O(h)
  • Edge cases: empty tree, single node, skewed tree
  • Iterative alternative using stack for deep trees

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

Q4

Return the actual leaf node where the maximum root-to-leaf path value is achieved.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Part three of the same problem and the one I fumbled most.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that the problem asks for the leaf node (not just the sum) where the maximum root-to-leaf path sum occurs. Use a recursive DFS that returns both the maximum sum and the corresponding leaf node, comparing left and right subtrees at each step. Handle edge cases like negative values and single-node trees.

Pro tip: Mention that if multiple leaves yield the same maximum sum, you should define a tie-breaking rule (e.g., leftmost leaf) and confirm with the interviewer. Also note that the algorithm runs in O(n) time and O(h) space, which is optimal.

1. Clarify the problem

Confirm that the goal is to return the leaf node itself, not the sum. Ask about tie-breaking (e.g., leftmost leaf) and whether the tree can be empty or contain negative values.

2. Define recursive function

Design a helper that takes a node and returns a pair: the maximum root-to-leaf sum from that node and the leaf node achieving it. For a leaf, return (node.val, node).

3. Combine results

For an internal node, recursively get results from left and right children. Add the node's value to the larger child sum (or handle ties) and return the updated sum and the corresponding leaf.

4. Handle edge cases

If the tree is empty, return null. If a node has only one child, use that child's result. Ensure negative values are handled correctly by comparing sums.

5. Analyze complexity

State that the algorithm visits each node once, so time is O(n) and space is O(h) due to recursion stack, where h is tree height.

Key Points to Mention

  • Recursive DFS with post-order traversal
  • Returning a pair (sum, leaf node) from each recursive call
  • Handling negative values and ties
  • Time complexity O(n) and space complexity O(h)
  • Edge cases: empty tree, single node, skewed tree
  • Clarifying tie-breaking rule with interviewer

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