← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
Jun 2026Remote

Summary

Uber phone screen for a SWE role, pretty much centered on the islands problem family. Nothing shocking but the streaming follow-up caught me more off guard than I expected.

Questions Asked (4)

Q1

Given a 2D grid of '1' (land) and '0' (water) cells, count the number of islands where an island is a group of land cells connected horizontally or vertically.

Algorithms & Data Structures
Author's notes

Went with DFS immediately, which was fine, but they pushed back and asked if I could do it with union-find instead.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints (grid size, connectivity definition) and discuss trade-offs between BFS, DFS, and Union-Find. Then implement a solution that traverses the grid, marking visited land cells and incrementing the island count for each unvisited land cell encountered.

Pro tip: Mention that you can optimize space by mutating the input grid (e.g., changing '1' to '0') if allowed, but always ask the interviewer first. Also, be prepared to discuss how to handle very large grids that don't fit in memory, showing awareness of scalability.

1. Clarify requirements and constraints

Ask about grid dimensions, whether the grid can be modified, and if diagonal connections count. Confirm the definition of an island and expected output.

2. Choose an algorithm

Decide between BFS, DFS, or Union-Find based on constraints. Discuss time and space complexity trade-offs for each.

3. Outline the approach

Explain how you will iterate through the grid, and for each unvisited land cell, perform a traversal to mark all connected land cells as visited, incrementing the island count.

4. Implement the solution

Write clean code for the chosen algorithm, handling edge cases like empty grid or all water. Use a visited set or modify the grid in-place.

5. Test and analyze

Walk through a small example, test edge cases, and state the time and space complexity (e.g., O(m*n) time, O(m*n) space for visited set or O(1) if modifying grid).

Key Points to Mention

  • Time and space complexity analysis: O(m*n) time, O(m*n) space for BFS/DFS with visited set, or O(1) extra space if modifying grid.
  • Choice of traversal: BFS vs DFS vs Union-Find, and when each is preferable (e.g., DFS recursion depth risk, Union-Find for dynamic connectivity).
  • Handling edge cases: empty grid, all water, all land, single row/column.
  • In-place modification vs using a separate visited set, and implications for input preservation.
  • Scalability considerations for very large grids (e.g., streaming, external memory).
  • Clear communication of thought process and trade-offs during problem-solving.

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

Q2

Follow-up: the grid is too large to fit in memory. How would you handle that?

Algorithms & Data StructuresTechnical Trade-offsSystem Design
Author's notes

Blanked for a second.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Acknowledge the memory constraint and pivot to external memory algorithms or streaming approaches. Discuss trade-offs between time, space, and complexity, and propose a concrete solution like chunked processing or distributed computing.

Pro tip: Mention that you would first clarify the exact constraints (e.g., grid size, available memory, time limits) before committing to a solution—this shows you think before coding.

1. Clarify constraints

Ask about the grid dimensions, available memory, time limits, and whether the grid is static or dynamic. This ensures you tailor the solution to the specific scenario.

2. Choose an external memory strategy

Decide between processing the grid in chunks (e.g., row-by-row or block-by-block) or using streaming algorithms if only a single pass is needed. Consider disk-based storage or memory-mapped files.

3. Design the algorithm

Outline how to process each chunk, maintain state (e.g., using a sliding window or boundary conditions), and combine results. For graph problems, consider partitioning the grid and handling cross-partition edges.

4. Address performance and trade-offs

Discuss I/O overhead, potential for parallelization, and whether a distributed approach (e.g., MapReduce, Spark) is warranted. Compare time and space complexity with the in-memory version.

5. Validate and iterate

Propose testing with smaller datasets and scaling up, and mention monitoring memory usage. Be open to refining the approach based on feedback.

Key Points to Mention

  • External memory algorithms (e.g., chunking, streaming)
  • Trade-offs between time, space, and complexity
  • Parallelization and distributed computing frameworks
  • Handling boundary conditions between chunks
  • I/O efficiency and memory-mapped files
  • Real-world examples like processing large graphs or images

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

Q3

Streaming variant: starting from an empty grid, you receive a sequence of addLand operations. After each operation, return the current island count.

Algorithms & Data Structures
Author's notes

This is LC 305 territory and I knew it existed but hadn't drilled it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the grid as a dynamic set of land cells and use Union-Find (Disjoint Set Union) to track connected components. For each addLand, increment the island count, then union the new cell with any adjacent land cells, decrementing the count for each successful union. This yields O(1) amortized time per operation with path compression and union by rank.

Pro tip: Discuss how to handle duplicate addLand calls (idempotency) and the trade-off between using a hash set versus a 2D array for sparse grids, showing awareness of memory constraints in a streaming context.

1. Clarify requirements and constraints

Ask about grid size, number of operations, whether duplicate adds are possible, and if the grid is sparse. This determines the data structures and optimizations.

2. Choose Union-Find with dynamic mapping

Use a hash map to map each land cell (row, col) to a unique parent index, and maintain a separate parent array for Union-Find. This handles sparse grids efficiently.

3. Process each addLand operation

If the cell is already land, return the current count. Otherwise, mark it as land, increment the island count, and for each of the four neighbors that are land, attempt to union; if union succeeds, decrement the count.

4. Implement Union-Find optimizations

Use path compression in find and union by rank/size to achieve near-constant time per operation. Ensure the parent array is dynamically extended as new cells are added.

5. Analyze complexity and edge cases

State that each operation is O(α(N)) amortized, where α is the inverse Ackermann function. Discuss edge cases like duplicate adds, out-of-bounds coordinates, and large sparse grids.

Key Points to Mention

  • Union-Find (Disjoint Set Union) with path compression and union by rank
  • Dynamic mapping of 2D coordinates to 1D indices using a hash map for sparse grids
  • Increment island count on new land, decrement on each successful union
  • Handling duplicate addLand operations idempotently
  • Time complexity: O(α(N)) per operation, effectively constant
  • Space complexity: O(K) where K is the number of land cells

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

Q4

Additional follow-up: after each addLand operation, also return the size of the largest island at that point.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Did not see this coming.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Treat the problem as a dynamic connectivity problem where each addLand operation can merge up to four neighboring islands. Use Union-Find (Disjoint Set Union) with union by rank and path compression to efficiently merge components, and maintain a running maximum island size by updating it after each union. For each addLand, check the four adjacent cells, union with existing land, and return the current max size.

Pro tip: Emphasize that the max size only increases or stays the same after each addLand, so you can update it incrementally rather than recomputing from scratch. Also, mention that using a 2D grid to track land is essential for O(1) neighbor checks.

1. Clarify requirements and constraints

Confirm that addLand operations are given as a stream and that after each operation we must return the size of the largest island. Discuss edge cases like duplicate land additions, out-of-bounds coordinates, and grid size limits.

2. Choose data structures

Use a 2D boolean grid to track land cells and a Union-Find structure to manage connected components. Each land cell maps to a unique parent index, and we maintain a size array for each root.

3. Design the addLand operation

For each addLand, if the cell is already land, return the current max size. Otherwise, mark it as land, initialize its Union-Find entry with size 1, and check its four neighbors. For each neighbor that is land, union the current cell with that neighbor, updating the size of the new root.

4. Maintain and return the maximum island size

Keep a variable maxSize that is updated after each union to be the maximum of its current value and the new component size. After processing all neighbors, return maxSize.

5. Analyze complexity and trade-offs

Explain that with path compression and union by rank, each operation is nearly O(1) amortized, leading to O(k α(n)) total time for k operations. Space is O(m*n) for the grid and Union-Find arrays. Discuss alternatives like DFS/BFS per operation, which would be less efficient.

Key Points to Mention

  • Union-Find with path compression and union by rank for near-constant time operations.
  • Maintaining a running maximum island size to avoid recomputation.
  • Checking all four adjacent cells (up, down, left, right) for connectivity.
  • Handling duplicate addLand calls by returning the current max size without changes.
  • Time complexity: O(k α(n)) for k operations, space complexity: O(m*n).
  • Trade-offs: Union-Find is optimal for dynamic connectivity; DFS/BFS would be O(m*n) per operation.

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