This question evaluates a candidate's ability to reason about shortest-paths and reachability on grid graphs, testing skills in graph traversal, distance computation, and spatial problem modeling within the Coding & Algorithms domain.
You are given an m x n grid of characters containing only:
'B'
= bathroom
'D'
= desk
'_'
= empty cell
From any cell you may move one step up/down/left/right (no diagonals). The distance between two cells is the length of the shortest such path.
For every desk cell 'D', compute the distance to its nearest bathroom 'B'.
Return an m x n integer matrix where:
-1
(or any clearly documented placeholder).
If a desk cannot reach any bathroom, return -1 for that desk.