← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Uber coding interview with a grid-based problem that looks approachable until you realize the naive approach is way too slow. The question had enough layers to keep me busy for the whole session.

Questions Asked (1)

Q1

You're given a 2D grid where each cell is a robot, empty, or an obstacle (grid boundaries also count as obstacles). You're also given a 4-element distance array representing how far a target robot is from the nearest obstacle in each direction (left, top, bottom, right). Find all robots in the grid whose distances to the nearest obstacle in all four directions match that profile exactly.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

My first instinct was to just iterate over every robot cell and scan outward in four directions each time.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases, then propose an efficient solution using precomputed directional distances. Discuss trade-offs between time and space complexity, and outline how to handle large grids.

Pro tip: Mention that you can precompute distances in O(mn) time using dynamic programming, and emphasize the importance of handling obstacles and boundaries uniformly to avoid off-by-one errors.

1. Clarify the problem

Ask questions to confirm the grid dimensions, obstacle representation, and whether the distance array is given for a specific robot or is a target profile. Ensure understanding of 'nearest obstacle' including boundaries.

2. Define the approach

Propose computing the distance to the nearest obstacle in each direction for every cell using dynamic programming. Then compare each robot's distances to the target profile.

3. Analyze complexity

State that the solution runs in O(mn) time and O(mn) space, which is optimal for this problem. Discuss potential optimizations if memory is a concern.

4. Handle edge cases

Consider grids with no obstacles, all obstacles, or robots on boundaries. Ensure the algorithm correctly treats boundaries as obstacles.

5. Test with examples

Walk through a small example to verify the logic, such as a 3x3 grid with a central robot and obstacles around, and check that the distances match the profile.

Key Points to Mention

  • Dynamic programming for directional distances (left, right, top, bottom)
  • Time and space complexity analysis (O(mn) time, O(mn) space)
  • Handling boundaries as obstacles
  • Comparing distance arrays for each robot
  • Potential optimizations (e.g., in-place computation, early termination)
  • Edge cases: empty grid, no obstacles, all obstacles

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