← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Uber coding screen for a software engineer role. One algorithmic problem, simulation-style, the kind that looks approachable until you're actually implementing it.

Questions Asked (1)

Q1

Given an m x n matrix of integers where equal values represent the same color, implement a single round of candy-crush style elimination: mark any cell for removal if at least 2 of its 4 neighbors share its value, set those cells to 0, then gravity-drop remaining values to the bottom of each column.

Algorithms & Data Structures
Author's notes

The removal condition tripped me up at first.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem constraints and edge cases, then propose a two-phase solution: marking cells for removal based on neighbor counts, followed by gravity-drop per column. Discuss time/space complexity and potential optimizations, and be prepared to code the solution.

Pro tip: Mention that you would use a copy of the matrix for marking to avoid cascading removals, and that gravity can be implemented efficiently with a two-pointer approach per column.

1. Clarify requirements and edge cases

Ask about matrix size limits, whether diagonal neighbors count, and if multiple rounds are needed. Confirm that only one round of elimination is performed.

2. Mark cells for removal

Iterate through each cell, count how many of its 4 neighbors (up, down, left, right) have the same value. If count >= 2, mark the cell for removal (e.g., in a separate boolean matrix or by setting to a sentinel).

3. Apply removal

Set all marked cells to 0. Ensure that marking is based on the original matrix to avoid cascading effects within the same round.

4. Apply gravity per column

For each column, use a two-pointer approach: one pointer from the bottom to place non-zero values, another to scan upwards. This compacts non-zero values to the bottom, filling the top with zeros.

5. Analyze complexity and test

State time complexity O(m*n) and space O(m*n) for the marking matrix (or O(1) if modifying in place with care). Walk through a small example to verify correctness.

Key Points to Mention

  • Use a separate boolean matrix or a copy to mark removals, preventing cascading removals in the same round.
  • Neighbor check: only 4-directional (up, down, left, right), not diagonal.
  • Gravity implementation: two-pointer technique per column for O(m) time per column, overall O(m*n).
  • Edge cases: empty matrix, single row/column, all cells same color, no cells to remove.
  • Time and space complexity analysis: O(m*n) time, O(m*n) space for marking matrix (or O(1) extra space if using sentinel values).
  • Potential follow-up: multiple rounds of elimination, which would require looping until no more removals.

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