← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Uber SWE coding round, one algorithmic problem the whole time. They pushed for a Union-Find solution specifically which I wasn't expecting since I'd always just defaulted to BFS for grid problems.

Questions Asked (1)

Q1

Given an m x n grid where '1' is land and '0' is water, count the number of islands. Islands are groups of land cells connected horizontally or vertically.

Algorithms & Data Structures
Author's notes

I know this problem cold with BFS but they wanted Union-Find, which I use way less often.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a graph traversal algorithm like BFS or DFS to explore each unvisited land cell and mark all connected land cells as visited, incrementing the island count for each new traversal. Alternatively, use Union-Find to group connected land cells and count distinct sets.

Pro tip: Discuss trade-offs between BFS, DFS, and Union-Find in terms of time/space complexity and practical considerations like recursion depth limits and input mutation. Mention that modifying the grid in-place can save space but may not be allowed; clarify with the interviewer.

1. Clarify requirements and constraints

Ask about grid size limits, whether the grid can be modified, and if diagonal connections count. Confirm that islands are only horizontally/vertically connected.

2. Choose an algorithm

Select BFS, DFS, or Union-Find based on constraints and your comfort. Explain why you chose it, considering time/space complexity and potential stack overflow with DFS.

3. Outline the traversal process

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

4. Analyze complexity and edge cases

State time complexity O(m*n) and space complexity O(m*n) in worst case. Discuss edge cases: empty grid, all water, all land, single row/column.

5. Discuss optimizations and alternatives

Mention in-place modification to save space, using iterative BFS to avoid recursion limits, and Union-Find with path compression and union by rank.

Key Points to Mention

  • Time and space complexity analysis for each approach
  • Handling of edge cases such as empty grid or no land
  • In-place modification versus using a visited matrix
  • Recursion depth concerns with DFS and iterative alternatives
  • Union-Find with path compression and union by rank
  • Clarifying assumptions about connectivity and grid mutability

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