← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Uber SWE coding round, just the one grid traversal problem. Pretty standard BFS territory but the constraints are large enough that you can't be sloppy about it.

Questions Asked (1)

Q1

Given an m x n grid of open cells (0) and walls (1), find the shortest path in steps from the top-left to the bottom-right cell moving only up/down/left/right. Return -1 if no path exists.

Algorithms & Data Structures
Author's notes

Classic BFS and I knew it immediately, which was both good and bad.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints (e.g., grid size, whether diagonal moves are allowed) and edge cases (start or end blocked). Then explain that BFS is optimal for unweighted shortest path, and outline the algorithm with a queue and visited set, analyzing time and space complexity.

Pro tip: Mention that BFS guarantees the shortest path in an unweighted grid, and proactively discuss how you'd handle large grids (e.g., using a 2D array for visited instead of a set for efficiency).

1. Clarify problem and edge cases

Ask about grid size limits, whether start/end can be walls, and if moves are only 4-directional. Confirm return value for no path.

2. Choose BFS and justify

Explain that BFS explores level by level, so the first time you reach the target, it's the shortest path. Mention that DFS would not guarantee shortest path.

3. Outline BFS algorithm

Use a queue initialized with start cell and distance 0. For each cell, check neighbors; if valid, unvisited, and open, enqueue with distance+1. Stop when target is reached.

4. Analyze complexity and optimizations

Time and space are O(m*n) since each cell is visited at most once. Suggest using a 2D boolean array for visited and early exit when target is found.

5. Test with examples

Walk through a small grid (e.g., 3x3 with a wall) to demonstrate correctness, including a case with no path returning -1.

Key Points to Mention

  • BFS is optimal for unweighted shortest path
  • Use a queue and track distance (either in queue or separate array)
  • Mark cells as visited to avoid cycles
  • Check boundaries and wall conditions before enqueueing
  • Time and space complexity: O(m*n)
  • Edge cases: start or end is a wall, no path exists

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