← Uber Interview Insights

Uber·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
Jun 2026

Summary

Did a coding round for a Software Engineer role at Uber, four algorithmic problems back to back. Nothing too wild in terms of topics but the combination lock one tripped me up more than I expected.

Questions Asked (4)

Q1

You have floors 1 through N and an API that tells you whether a given floor is safe for elevator operation. There's a threshold floor T where everything at or below is safe and everything above is not. Find T using only O(log N) API calls.

Algorithms & Data Structures
Author's notes

Pretty transparent binary search setup once you see it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Recognize this as a classic binary search problem where the API acts as a monotonic predicate. Use binary search to find the largest floor where the API returns 'safe', which is the threshold T, ensuring O(log N) API calls.

Pro tip: Clarify edge cases upfront (e.g., if all floors are unsafe or all safe) and discuss how to handle them within the binary search to avoid off-by-one errors.

1. Understand the problem and constraints

Restate the problem: floors 1 to N, API returns safe/unsafe, find T such that floors ≤ T are safe and > T are unsafe. Emphasize the O(log N) API call constraint.

2. Identify the monotonic property

Explain that the safety predicate is monotonic: if a floor is safe, all lower floors are safe; if unsafe, all higher floors are unsafe. This enables binary search.

3. Design the binary search algorithm

Initialize low=1, high=N. While low <= high, compute mid, call API. If safe, record mid as candidate T and search higher (low=mid+1); else search lower (high=mid-1).

4. Handle edge cases and return T

After loop, return the last safe floor found. If no safe floor, T=0 (or indicate none). If all safe, T=N. Discuss how the algorithm naturally handles these.

5. Analyze complexity and test

State that each iteration halves the search space, so O(log N) API calls. Walk through a small example (e.g., N=10, T=6) to verify correctness.

Key Points to Mention

  • Binary search on the answer space (floors)
  • Monotonicity of the safety predicate
  • Time complexity: O(log N) API calls
  • Edge cases: T=0 (no safe floors), T=N (all safe)
  • Use of low, high, and mid pointers with careful boundary updates
  • Returning the largest safe floor as T

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

Q2

A combination lock has four wheels, each ranging from 0 to 9 with wraparound. Each move changes exactly one wheel by one step. Given a start state, a target state, and a list of blocked states you cannot pass through, return the minimum number of moves to reach the target or -1 if it's impossible.

Algorithms & Data Structures
Author's notes

This one got me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a shortest path in a graph where each state is a 4-digit combination and edges represent single-wheel moves. Use BFS from the start state, skipping blocked states, and return the distance when the target is reached or -1 if exhausted.

Pro tip: Mention that BFS is optimal for unweighted graphs and that bidirectional BFS can significantly reduce the search space, especially when the target is far. Also, pre-check if start or target is blocked to return -1 immediately.

1. Clarify and Validate

Confirm input format, edge cases (start equals target, blocked start/target), and that moves are bidirectional with wraparound. Ask if the lock can have repeated states or if blocked states are guaranteed unique.

2. Model as Graph

Represent each combination as a node (e.g., integer 0000-9999). Edges connect states differing by one wheel ±1 mod 10. Blocked states are removed from the graph.

3. Choose BFS

Use BFS to find the shortest path because all edges have unit weight. Initialize a queue with the start state, a visited set, and a distance counter.

4. Implement BFS

While queue is not empty, dequeue a state. If it's the target, return distance. Otherwise, generate all 8 neighbors (each wheel +1/-1 mod 10), skip blocked or visited states, mark visited, and enqueue with distance+1.

5. Handle Impossibility

If BFS exhausts without reaching the target, return -1. Also, early return -1 if start or target is blocked.

Key Points to Mention

  • BFS guarantees shortest path in unweighted graphs.
  • State space is at most 10^4 = 10,000 states, so BFS is efficient.
  • Use a visited set to avoid cycles and redundant work.
  • Generate neighbors by adding/subtracting 1 modulo 10 for each wheel.
  • Early termination if start or target is blocked.
  • Optional: bidirectional BFS for optimization.

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

Q3

Given a 2D grid with walls and open cells, and a starting position inside the grid, find the minimum number of moves to reach any open cell on the boundary of the grid that isn't the starting cell. Return -1 if no such exit is reachable.

Algorithms & Data Structures
Author's notes

Standard BFS grid question.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the grid as a graph where each open cell is a node and edges connect adjacent open cells. Use BFS from the starting position to compute the shortest distance to any boundary open cell (excluding the start), returning the minimum distance or -1 if unreachable.

Pro tip: Clarify edge cases upfront: if the start is already on the boundary, you still need to find another boundary cell; also confirm whether diagonal moves are allowed. This shows attention to detail and avoids incorrect assumptions.

1. Clarify problem constraints and edge cases

Ask about grid size, movement directions (4 or 8), and whether the starting cell can be a boundary cell. Confirm that the exit must be a different open boundary cell.

2. Choose BFS for shortest path in unweighted grid

Explain that BFS guarantees the shortest path in an unweighted graph. Initialize a queue with the start position and a visited set or distance matrix.

3. Perform BFS while checking for boundary exits

Process cells level by level, and when dequeuing a cell, check if it's on the boundary and not the start. If so, return the current distance.

4. Handle unreachable cases and return -1

If the queue empties without finding a valid boundary cell, return -1. Also consider early termination if the start is surrounded by walls.

5. Analyze time and space complexity

State that time complexity is O(m*n) since each cell is visited at most once, and space complexity is O(m*n) for the queue and visited set.

Key Points to Mention

  • BFS is optimal for unweighted shortest path problems.
  • Use a queue and a visited set (or distance matrix) to avoid revisiting cells.
  • Check boundary condition when processing each cell, not just when enqueuing.
  • Exclude the starting cell from being considered a valid exit.
  • Handle edge cases: start on boundary, no open boundary cells, start surrounded by walls.
  • Time and space complexity: O(m*n) where m and n are grid dimensions.

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

Q4

Generate a minesweeper board: given dimensions and a mine count N, randomly place N mines in distinct cells, then fill every non-mine cell with the count of mines in its eight neighboring cells. Focus on clean, simple code without unnecessary extra data structures.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The random placement part is where people overthink it and I was no exception.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints and edge cases, then outline a simple algorithm: create a 2D array, randomly place mines using a set or shuffle to ensure distinct cells, and compute neighbor counts by iterating over each cell. Emphasize clean code by avoiding unnecessary data structures and using helper functions for clarity.

Pro tip: Mention that you can avoid a separate mine placement data structure by using a sentinel value (e.g., -1) to mark mines, then compute counts in a single pass. This demonstrates awareness of memory and simplicity trade-offs.

1. Clarify requirements and edge cases

Ask about board dimensions, mine count validity (e.g., N <= rows*cols), and expected output format. Discuss edge cases like zero mines or full board.

2. Design the data structure

Choose a 2D array (list of lists) to represent the board. Use a sentinel value (e.g., -1) for mines to avoid a separate boolean array.

3. Place mines randomly

Generate N distinct random positions. Use a set to track placed mines or shuffle a list of all cells and take the first N.

4. Compute neighbor counts

Iterate over each non-mine cell and count mines in its eight neighbors using boundary checks. Update the cell with the count.

5. Review and test

Walk through a small example to verify correctness. Discuss time and space complexity (O(rows*cols) time, O(rows*cols) space).

Key Points to Mention

  • Random placement with distinct cells: use a set or shuffle to avoid duplicates.
  • Sentinel value for mines to keep code clean and avoid extra data structures.
  • Boundary checks when counting neighbors to prevent index out-of-bounds.
  • Time and space complexity: O(R*C) time and space, which is optimal.
  • Edge cases: N=0, N=R*C, and handling invalid input.
  • Code clarity: use helper functions for neighbor iteration and mine placement.

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