← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Uber software engineer interview with a classic grid traversal problem. Nothing too exotic but it's the kind of question where you either know BFS/DFS cold or you don't, and the pressure of an actual interview has a way of making you second-guess yourself.

Questions Asked (1)

Q1

Given a 2D binary grid representing a map of land ('1') and water ('0'), count the number of islands. An island is a group of horizontally or vertically connected land cells, and the grid is surrounded by water on all edges.

Algorithms & Data Structures
Author's notes

I went with DFS and it worked fine, but I wasted probably two minutes overthinking whether BFS would be more impressive.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use DFS or BFS to traverse the grid, counting each unvisited land cell as a new island and marking all connected land cells as visited. Alternatively, use Union-Find to group connected land cells and count distinct sets. Discuss trade-offs between approaches.

Pro tip: Mention that you can optimize space by modifying the grid in-place (e.g., changing '1' to '0') instead of using a separate visited array, but clarify if the input can be mutated. Also, consider iterative DFS to avoid stack overflow for large grids.

1. Clarify the problem

Confirm grid dimensions, connectivity (4-directional), and whether the grid can be modified. Ask about edge cases like empty grid or all water.

2. Choose an algorithm

Select DFS, BFS, or Union-Find based on constraints and preferences. Explain why (e.g., DFS is simple, Union-Find is good for dynamic connectivity).

3. Outline the traversal

Iterate through each cell; when encountering unvisited land, increment island count and traverse all connected land cells, marking them visited.

4. Analyze complexity

State time complexity O(M*N) and space complexity O(M*N) for visited array or recursion stack, or O(M*N) for Union-Find.

5. Test with examples

Walk through a small example (e.g., 3x3 grid) to verify the approach and handle edge cases like single cell or diagonal connections.

Key Points to Mention

  • Time and space complexity analysis
  • Handling of edge cases (empty grid, all land, all water)
  • Choice of traversal method (DFS vs BFS vs Union-Find) and trade-offs
  • In-place modification vs separate visited array
  • Recursion depth concerns and iterative alternatives
  • Connectivity definition (4-directional vs 8-directional)

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