My first instinct was to just BFS from every robot cell and call it a day.
Precompute the distance to the nearest obstacle in each of the four directions for every cell using four directional passes (left-to-right, right-to-left, top-to-bottom, bottom-to-top). Then iterate through the grid, and for each robot cell, compare its precomputed distance tuple with the target tuple, collecting matching coordinates. This approach runs in O(m*n) time and space, which is optimal for grid traversal.
Pro tip: Clarify upfront that robots are not obstacles, so distance calculations should only consider obstacle cells. Also, handle edge cases like no obstacles (distances to grid boundaries) and robots on the grid edges.
Confirm that robots do not block distances and that distances are measured to the nearest obstacle in each direction, not to the grid boundary. Ask about grid size and whether multiple robots can share a cell.
Use four 2D arrays to store distances to the nearest obstacle in left, up, right, and down directions. Initialize distances to infinity or a large number, then update during directional scans.
For left distances, scan each row left-to-right: if cell is obstacle, set distance 0; else distance = previous cell's distance + 1. Similarly, scan right-to-left for right distances, top-to-bottom for up distances, and bottom-to-top for down distances.
Iterate over all cells; if the cell contains a robot, check if its four precomputed distances equal the target tuple. If so, add its coordinates to the result list.
State that time and space complexity are O(m*n). Discuss edge cases: no obstacles, robots at boundaries, and target tuple with large distances.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.