← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Three coding problems back to back for a Software Engineer role at Uber. Nothing behavioral, just pure algorithms the whole way through. The problems ranged from a greedy assignment problem to a tree edge-reversal thing I hadn't seen before, plus a classic binary matrix search.

Questions Asked (3)

Q1

You have n tasks that must be split between two workers. Worker 1 must get exactly k tasks. Each task has a reward value depending on which worker does it. How do you assign tasks to maximize total reward?

Algorithms & Data Structures
Author's notes

The greedy insight is to think about the 'cost' of giving a task to worker 1 versus worker 2, specifically the difference reward1[i] minus reward2[i].

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as maximizing total reward with a cardinality constraint: assign each task to the worker giving higher reward, but if the count of tasks assigned to Worker 1 exceeds k, switch the k tasks with the smallest penalty (difference between rewards) to Worker 2. Alternatively, use a greedy approach with a priority queue or sort by penalty. Explain the algorithm, prove correctness, and analyze time complexity.

Pro tip: Emphasize that the greedy choice is optimal because the penalty for switching a task is independent of other assignments, and mention that this can be solved in O(n log n) time, which is efficient for large n.

1. Understand the problem

Clarify that each task has two rewards: one for Worker 1 and one for Worker 2. Worker 1 must get exactly k tasks, Worker 2 gets the rest. Goal: maximize sum of rewards.

2. Initial assignment

Assign each task to the worker who gives the higher reward. Count how many tasks are assigned to Worker 1.

3. Adjust to meet constraint

If Worker 1 has more than k tasks, compute the penalty (reward1 - reward2) for each task assigned to Worker 1. Switch the tasks with the smallest penalties to Worker 2 until Worker 1 has exactly k tasks.

4. Handle edge cases

If initial assignment gives Worker 1 fewer than k tasks, switch tasks from Worker 2 to Worker 1, choosing those with the largest gain (reward1 - reward2).

5. Analyze complexity

Sorting tasks by penalty/gain takes O(n log n) time, and the rest is O(n). Space is O(n) for storing tasks.

Key Points to Mention

  • Greedy algorithm: start with optimal unconstrained assignment, then adjust to meet cardinality constraint.
  • Penalty/gain calculation: difference between rewards for each task.
  • Sorting by penalty/gain to select which tasks to switch.
  • Time complexity: O(n log n) due to sorting.
  • Proof of optimality: exchange argument showing that any optimal solution must switch the tasks with smallest penalties.
  • Edge cases: k=0, k=n, or when initial assignment already satisfies constraint.

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

Q2

Given a directed tree (connected, acyclic if you ignore directions) with n nodes and n-1 edges, find the minimum number of edge reversals needed so that every node has a directed path to some single root node r. Minimize over all possible choices of r.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This one wrecked me a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as finding a root that minimizes the number of edges directed away from it. For each node, compute the number of edges that need reversal if it were the root, using two DFS passes to accumulate counts efficiently. Then return the minimum count over all nodes.

Pro tip: Start by explaining the brute-force O(n^2) approach and then optimize to O(n) using rerooting DP. This shows you can think iteratively and care about efficiency, which is crucial for large-scale systems at Uber.

1. Understand the problem

Clarify that we need to choose a root r and reverse edges so that all nodes can reach r. The goal is to minimize reversals over all r.

2. Brute-force approach

For each node as root, perform a DFS to count edges that point away from the root (i.e., need reversal). This takes O(n^2) time.

3. Optimize with rerooting DP

First, root the tree arbitrarily (e.g., at node 0) and compute the number of reversals needed for that root. Then, use a second DFS to compute the count for all other nodes by adjusting based on the edge between parent and child.

4. Implement and analyze

Write code to perform the two DFS passes, track the minimum reversals, and return the optimal root. Analyze time and space complexity as O(n).

Key Points to Mention

  • The problem is equivalent to finding a root that minimizes the number of edges directed away from it.
  • Brute-force O(n^2) is straightforward but inefficient; rerooting DP reduces it to O(n).
  • Rerooting DP: compute initial count for an arbitrary root, then propagate changes when moving the root along an edge.
  • When moving root from u to v, if edge u->v exists, reversals decrease by 1; if v->u, reversals increase by 1.
  • The answer is the minimum count over all nodes, and the root achieving it is the optimal root.
  • Edge cases: n=1 (0 reversals), star graphs, and paths.

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

Q3

Given a binary matrix where every row is sorted (all 0s before all 1s), find the index of the leftmost column that contains at least one 1. Your solution must be faster than O(m*n).

Algorithms & Data Structures
Author's notes

Classic.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start from the top-right corner of the matrix and move left whenever you encounter a 1, or down whenever you encounter a 0. This staircase traversal finds the leftmost column with a 1 in O(m + n) time, which is faster than O(m*n).

Pro tip: Explicitly state the time and space complexity and compare it to the brute-force approach. Mention that the matrix is sorted, which allows the staircase optimization, and handle edge cases like no 1s present.

1. Clarify the problem

Confirm that the matrix is binary, each row is sorted (0s then 1s), and we need the leftmost column index containing at least one 1. Ask about edge cases: what if no 1 exists? What if multiple 1s in a column?

2. Discuss brute-force and its complexity

Mention that checking every cell takes O(m*n) time, which is too slow. This sets the stage for a better approach.

3. Introduce the staircase traversal

Start at the top-right cell. If it's 1, record the column and move left; if it's 0, move down. Repeat until out of bounds. This works because rows are sorted.

4. Analyze complexity and edge cases

The algorithm moves at most m steps down and n steps left, so O(m+n) time and O(1) space. Handle cases where no 1 is found by returning -1.

5. Test with examples

Walk through a small example to verify correctness, such as a 3x4 matrix, and check edge cases like all zeros or all ones.

Key Points to Mention

  • Time complexity O(m+n) and space complexity O(1)
  • Leveraging the sorted property of rows to eliminate columns/rows
  • Starting from top-right corner to efficiently narrow down the leftmost column
  • Handling edge cases: no 1s present, single row/column, all 1s
  • Comparison with binary search per row (O(m log n)) and why staircase is better
  • Correctness proof: invariant that all columns to the right of current column have no 1s

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