Find Robots by Blocker Distances
Reported by candidates from Uber's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The edge case that kills the naive solution in this Uber OA, reported October 2026, is the out-of-bounds step. Forget to count it and every robot on the border returns the wrong distance. The problem is a grid scan: for each robot, find the distance to the nearest X in four directions and compare against the query [left, top, bottom, right]. Grids go up to 200x200, so brute force per robot might pass, but it's sloppy. If you blank on the precompute or the off-by-one, StealthCoder runs invisibly during the live assessment and gives you a working solution so one slip doesn't sink the attempt.
The problem
Given a non-empty rectangular grid grid and a four-element array query, return the coordinates of every robot whose nearest-blocker distances match query. Each grid cell is one of: O: a robot. E: an empty cell. X: a blocker. The query order is [left, top, bottom, right]. In one direction, the distance is the number of steps from the robot to the first X cell. If there is no blocker before the grid edge, use the number of steps to the first out-of-bounds position. The blocker or out-of-bounds step is included in the distance. Return zero-based [row, column] pairs in row-major order. Function findRobots(grid: String[], query: int[]) → int[][] Examples Example 1 grid = ["OEEEX","EOXXX","EEEEE","XEOEE","XEXEX"] query = [2,2,4,1] return = [[1,1]] The robot at [1,1] is two steps from the left boundary, two steps from the top boundary, four steps from the bottom boundary, and one step from the blocker on its right. Example 2 grid = ["O"] query = [1,1,1,1] return = [[0,0]] Every direction reaches the first out-of-bounds position in one step. Example 3 grid = ["XOXOX","XXXXX","XOXOX"] query = [1,1,1,1] return = [[0,1],[0,3],[2,1],[2,3]] Each robot is immediately surrounded by blockers or a grid boundary, so all four coordinates match and are returned in row-major order. Constraints 1 <= grid.length <= 200. 1 <= grid[i].length <= 200. Every row has the same length. Every cell is exactly O, E, or X. query.length == 4. Every query distance is positive and at most max(grid.length, grid[0].length) + 1.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is precomputing four distance tables instead of walking from every robot. Sweep each row left to right, tracking the column of the last X seen, starting at -1 to represent the out-of-bounds position. For a cell at column c, left distance is c minus that last blocker column. Sweep right to left for the right distance, with the sentinel at width. Do the same down and up the columns for top and bottom. Then loop in row-major order, and for every O cell compare the four values to the query. Row-major iteration gives you the required output order for free. The pitfall is the off-by-one: the blocker or boundary step counts, so a robot at column 0 has left distance 1. Example 2 confirms it. Also remember the query order is left, top, bottom, right, not the clockwise order. If the live OA rattles you, StealthCoder is the hedge that catches a botched sentinel.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Find Robots by Blocker Distances cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Uber's OA.
Uber reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Find Robots by Blocker Distances FAQ
How hard is Find Robots by Blocker Distances really?+
Easy to medium. There's no fancy algorithm, just careful indexing. The 200x200 limit means even a per-robot scan likely runs fine, but the precompute approach is cleaner and safer. Most failures come from the off-by-one on boundaries, not the logic.
What's the trick to getting the distances right?+
Treat the out-of-bounds position as a blocker at index -1 on the near side and at length on the far side. Then distance is just the difference between indices. Example 2, a single O with query [1,1,1,1], is your sanity check.
Does the query order matter?+
Yes. It's [left, top, bottom, right], which isn't clockwise. Mixing up top and bottom or right and left is an easy way to pass example 1 by luck and fail hidden tests. Write the order as a comment before you code.
How should I order the output?+
Row-major. Iterate rows in the outer loop and columns in the inner loop, and append matching robots as you find them. No sorting is needed. Coordinates are zero-based [row, column] pairs, as shown in example 3.
How do I prepare for this in 48 hours?+
Practice one grid problem where you precompute directional arrays with forward and backward sweeps. Then write this one from scratch and test the three examples by hand. Focus on boundary handling for single-cell grids and robots on edges.