Closest Bathroom / Desk on a Grid

Asked at Snowflake · Coding Questions · Difficulty: Medium · Last asked Jul 1, 2026

Given a 2-D grid with cells marked `B` (bathroom), `D` (desk), and `_` (empty), return the shortest 4-directional step distance from each cell to its nearest bathroom. Bathroom cells are distance 0; unreachable cells are -1.

Loading the problem…