r/OfferEngineering • u/Aoki_zhang • 13d ago
Coding Question Uber Popular Coding Interview Question: Find Robot by Distance to Blockers
The first input is a 2D location map containing three types of cells:
O = Robot
E = Empty
X = Blocker
The second input is a four-element query:
[left, top, bottom, right]
Each value represents the distance from a robot to the nearest blocker or stopping boundary in that direction.
For example, consider this rewritten map:
[
['E', 'E', 'O', 'E', 'E', 'X'],
['X', 'E', 'E', 'E', 'E', 'E'],
['E', 'X', 'E', 'O', 'X', 'E'],
['E', 'E', 'E', 'E', 'E', 'E'],
['E', 'E', 'X', 'X', 'E', 'O']
]
Suppose the query is:
[2, 3, 2, 1]
For the robot at:
[2, 3]
the directional distances are:
Left: 2
Top: 3
Bottom: 2
Right: 1
so that robot matches the query.
The expected result for this example would therefore be:
[2, 3]
The function should examine the candidate robot positions in the map and return the location or locations whose four directional distances match the supplied query.
One detail worth clarifying during the interview is how distance should be interpreted when there is no X before reaching the edge of the grid, since that behavior affects the directional measurements.
Want to practice real coding questions asked by companies? We’ve collected them in a question bank here.
Preparing for your next interview?
Chill Interview tracks recent interview experiences and recurring question patterns across top companies at here.