Choose One Blocker Removal for the Fastest Grid Signals
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: Choose at most one global blocker removal to minimize the time for all grid targets to receive signals, with deterministic tie-breaking.
Read the full Google Software Engineer interview experience this question came from
Constraints
- The rectangular grid has 1 through 30 rows and columns, with equal-length strings using only S, B, T and period.
- All sources propagate simultaneously at time zero; one orthogonal step costs one unit and every non-blocker cell is traversable.
- At most one blocker is removed globally before propagation, with no removal-time cost; all signal paths share that fixed choice.
- Minimize the maximum target first-arrival time. Prefer no removal on an optimal tie, then the smallest removal row and column.
- No targets returns [0,-1,-1]. No permitted choice reaching all targets returns [-1,-1,-1], including targets with no source.
Examples
Input: (['SBT'],)
Expected Output: [2, 0, 1]
Explanation: Published sample 1: removing the middle blocker creates the two-step route.
Input: (['SBT', 'BBB', 'TBS'],)
Expected Output: [-1, -1, -1]
Explanation: Published sample 2: the two targets require incompatible removals; no single globally shared blocker suffices.
Community answers
Answer by chandanagrawal23