← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Uber SWE coding round, pretty much a straight grid traversal problem. Nothing too surprising but the pressure to pick the right approach on the spot is real.

Questions Asked (1)

Q1

Given a 2D binary grid where '1' represents land and '0' represents water, count the number of distinct islands. Islands are groups of adjacent land cells connected horizontally or vertically, and the grid boundary is all water.

Algorithms & Data Structures
Author's notes

I went with BFS because DFS felt like it might blow the stack on a big grid and I said that out loud which I think was fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Treat the grid as a graph and use DFS/BFS to explore each unvisited land cell, marking all connected land cells as visited to count one island. Iterate through every cell, and when an unvisited '1' is found, increment the island count and flood-fill to mark the entire island.

Pro tip: Clarify edge cases upfront (empty grid, all water, all land) and discuss trade-offs between DFS (recursive, risk of stack overflow) and BFS (iterative, uses queue). Mention that modifying the grid in-place is acceptable if allowed, otherwise use a visited set.

1. Clarify problem and constraints

Confirm grid dimensions, whether diagonal connections count (they don't), and if modifying the input is allowed. Discuss edge cases like empty grid or no land.

2. Choose traversal method

Decide between DFS (recursive or iterative) and BFS. Explain why one might be preferred (e.g., DFS simpler, BFS avoids recursion depth issues).

3. Implement island counting

Iterate through each cell. When an unvisited '1' is found, increment count and perform traversal to mark all connected land cells as visited (e.g., set to '0' or use visited set).

4. Analyze complexity

State time complexity O(M*N) since each cell visited once, and space complexity O(M*N) worst-case for recursion stack or queue.

5. Test with examples

Walk through a small example to verify correctness, including edge cases like single cell, multiple islands, and no islands.

Key Points to Mention

  • Graph traversal (DFS/BFS) to explore connected components
  • In-place modification vs. separate visited set
  • Time and space complexity analysis
  • Handling edge cases (empty grid, all water, all land)
  • Direction arrays for 4-directional adjacency
  • Recursion depth concerns and iterative alternatives

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