AO
Back

Find Robots Matching Distances to the Nearest Blockers

Also reported as Find Robot by Distance to Blockers · Find Robots Position

Phone ScreenPhone ScreenLast reported October 2026Medium Frequency

Problem Overview

The round: nine reports from November 2025 to October 2026: seven phone screens (about 20 minutes of coding next to a project deep dive; one had 45 minutes of coding and 15 of design), one onsite round, and one round whose format is not stated. Every report describes the same task; two give the full example map. Two reports describe the same push: brute force first, then precompute the distances in four directions. Two graded parts here: one query, then many queries on the same map.

You get a map, a list of rows where "O" is a robot, "E" is empty and "X" is a blocker, and a query of four distances to the closest blocker, by default in the order [left, top, bottom, right]. The edge of the map also counts as a blocker.

O E E E X        query [2, 2, 4, 1]  ->  [[1, 1]]
E O X X X
E E E E E        robot [1, 1]: left 2 (edge), top 2 (edge),
X E O E E                      bottom 4 (edge), right 1 (the X next to it)
X E X E X

Distance is the index gap. A blocker in the next cell is distance 1, and the edge sits one step past the last cell. That is the only reading under which the reported example gives [1, 1]; counting just the empty cells in between gives [1, 1, 3, 0] for that robot.

Part 1 — find the robots that match one query

def find_robots(grid: list, query: list, order: str = "ltbr") -> list: ...
  • Return [row, col] for every robot whose four distances equal the query, in row-major order, or [] when none does. Several robots can match.
  • Only "X" and the edge block. Another robot in the way does not.
  • order says which direction each query slot is. Most reports give left, top, bottom, right ("ltbr"); one gives left, top, right, bottom ("ltrb"). The same four numbers find different robots under the two orders, so ask.

Part 2 — answer many queries on the same map

class RobotFinder:
    def __init__(self, grid: list): ...
    def find(self, query: list, order: str = "ltbr") -> list: ...
  • Same answer as Part 1, but the map is fixed and find is called many times (the stress test asks 4,000 queries on a 300 x 300 map). Do the per-map work once in the constructor.

Notes: the function and class names, the order parameter, the row-major output and Part 2's many-queries framing are ours. In the reports the interviewer asked for something better than brute force without naming a scenario; commenters on one report debate whether a single query justifies the precompute.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Trade-off discussion · 2
Trade-off discussion

Can you do better? Is there a way to precompute and speed this up?

Probes for: Candidate presents brute-force solution

What scenario justifies the precomputation overhead?

Probes for: Candidate proposes optimization

Approach Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
Brute-force ray casting per robotsimple; O(M*N*(M+N)) per query in the worst case. One interviewer said brute force was fine to implement; others pushed for better.
Precompute four-direction DP arraysO(M*N) preprocessing, then each query is a lookup if robots are indexed by their four distances; the passes need careful index management, which one report calls the hard part.

What Reports Emphasize

Common mistakes: Stopping at brute force: one interviewer was not satisfied with the brute-force explanation and asked for something better, and one candidate who knew it called for DP could only write brute force.; Mixing up direction indices: one report calls this the hard part of the problem. Check the query order too: most reports give [left, top, bottom, right], one gives left, top, right, bottom.; Counting only the empty cells between the robot and the blocker: the reported example ([2, 2, 4, 1] gives the robot at [1, 1]) needs the index gap, so a blocker in the next cell is distance 1.

Interviewer hints: At least one interviewer did not provide a scenario to motivate the optimization and simply asked 'is there a better way?' after the brute-force explanation.; One interviewer emphasised communication and implementation, said implementing brute force was fine, and said it was acceptable even not to finish.; One interviewer gave no test cases on HackerRank and did not ask for any; a verbal dry run of the given example was enough to move on to design.

What passers do: One candidate who got an onsite invite discussed brute force, then precomputing the four directional distances, and wrote the optimised version; the interviewer had not said what scenario called for optimising.

Edge cases to test: Grid boundary counts as a blocker (a robot in column 0 has left distance 1); Robot adjacent to a blocker (distance = 1); Robot at a corner of the grid; Multiple robots in the grid, only some match the query; Whether other robots block: in the reported examples only 'X' and the boundary are blockers, so confirm before treating 'O' as open.

Practice

Write your own against 9 test cases, or read the worked solution — approach, complexity, and code that runs.

Prepping for Uber with friends?

Send them this page. It is free to read, no account needed.

More Uber Questions

Free preview

Every question in the Uber catalog gets this depth

What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 83 Uber questions, refreshed monthly from new candidate reports.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Uber · Phone Screen · Reported 9× across candidate reports
Is this helpful?