You are given a 2D grid and a distance signature dist = [left, top, bottom, right].
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).
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:
0
.
X
) block the line of sight; only the nearest obstacle in that direction matters.
Return the coordinates of all robots (O cells) whose distance signature equals the given dist.
grid
as an
R x C
matrix of characters, and integer array
dist
of length 4.
[(r1,c1), (r2,c2), ...]
for all matching robots (any order).
1 <= R, C <= 2000
grid[r][c] ∈ { 'O', 'E', 'X' }
0 <= dist[i] <= max(R,C)