← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Uber SWE interview that included at least one coding problem. Nothing too surprising if you've done your prep.

Questions Asked (1)

Q1

Solve the Number of Islands II problem.

Algorithms & Data Structures
Author's notes

Classic Union Find problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use Union-Find (Disjoint Set Union) to dynamically maintain connected components as land is added. For each new land position, increment the island count, then union with any adjacent existing land, decrementing the count for each successful union. This yields near O(k α(n)) time for k additions.

Pro tip: Mention that Union-Find with union by rank and path compression is optimal here, and discuss how you'd handle edge cases like duplicate positions or out-of-bounds coordinates. Also, note that a naive BFS/DFS per addition would be O(k * m*n) and is inefficient.

1. Clarify the problem and constraints

Confirm that the grid starts empty and positions are added one by one, and that you need to return the number of islands after each addition. Ask about grid size limits and whether duplicate positions can occur.

2. Choose the right data structure

Select Union-Find (Disjoint Set Union) with path compression and union by rank/size to efficiently track connected components. Explain why it's better than BFS/DFS for incremental updates.

3. Design the algorithm

Initialize a parent array for all cells (or a hash map for sparse grids) and a count of islands. For each added land, mark it as land, increment island count, then check its four neighbors: if a neighbor is land and not already connected, union them and decrement island count.

4. Handle edge cases and duplicates

If a position is already land, skip processing and return the current count. Ensure boundary checks for neighbors. Consider using a 2D-to-1D index mapping for efficiency.

5. Analyze complexity and test

State time complexity: O(k α(m*n)) where k is number of additions, and space O(m*n). Walk through a small example to verify correctness, and discuss potential optimizations like early termination if no neighbors.

Key Points to Mention

  • Union-Find (Disjoint Set Union) with path compression and union by rank
  • Incremental island count update: +1 for new land, -1 for each successful union
  • Handling duplicate positions and out-of-bounds neighbors
  • Time complexity O(k α(n)) vs. naive O(k * m*n) BFS/DFS
  • Space complexity O(m*n) for parent array or O(k) for hash map if sparse
  • Edge cases: empty grid, single cell, all water, all land

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