Find robots matching obstacle-distance signature
Company: Uber
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
You are given a 2D grid and a distance signature `dist = [left, top, bottom, right]`.
## Grid
Each cell is one of:
- `O` : a robot
- `E` : empty
- `X` : obstacle
The **boundary outside the grid is also considered an obstacle** (i.e., moving off the grid in any direction hits an obstacle immediately).
## Distance signature
For any cell `(r, c)`, define:
- `left` = the number of **non-obstacle cells** strictly between `(r,c)` and the nearest obstacle when moving left in the same row.
- `top` = the number of non-obstacle cells strictly between `(r,c)` and the nearest obstacle when moving up in the same column.
- `bottom` = the number of non-obstacle cells strictly between `(r,c)` and the nearest obstacle when moving down in the same column.
- `right` = the number of non-obstacle cells strictly between `(r,c)` and the nearest obstacle when moving right in the same row.
Notes:
- If the adjacent cell in that direction is an obstacle (or you would immediately leave the grid), the distance in that direction is `0`.
- Obstacles (`X`) block the line of sight; only the nearest obstacle in that direction matters.
## Task
Return the coordinates of **all robots** (`O` cells) whose distance signature equals the given `dist`.
## Input / Output (you may assume)
- Input: `grid` as an `R x C` matrix of characters, and integer array `dist` of length 4.
- Output: a list of coordinates `[(r1,c1), (r2,c2), ...]` for all matching robots (any order).
## Constraints (reasonable interview assumptions)
- `1 <= R, C <= 2000`
- `grid[r][c] ∈ { 'O', 'E', 'X' }`
- `0 <= dist[i] <= max(R,C)`
Quick Answer: This question evaluates spatial reasoning on 2D grids, the ability to compute distance signatures to nearest obstacles, and careful handling of boundary and edge-case conditions.