Find the Time for Grid Signals to Reach Every Target
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: Find when simultaneous grid signals reach every target while blockers prevent propagation, including unreachable targets and empty target sets.
Read the full Google Software Engineer interview experience this question came from
Constraints
- The rectangular grid has 1 through 200 equal-length rows and 1 through 200 columns, using only S, B, T and period.
- Every source starts at time zero. Movement is orthogonal, takes one unit per edge, and may pass through sources and targets.
- Blockers are not traversable; no removal or diagonal movement is permitted.
- Return the latest first-arrival time over all targets, zero if there are no targets, and -1 if any target is unreachable.
Examples
Input: (['S.BT', '.B..', 'T..S'],)
Expected Output: 2
Explanation: Published sample 1: the two targets receive independent simultaneous arrivals of two steps from different sources.
Input: (['SBT'],)
Expected Output: -1
Explanation: Published sample 2: the blocker separates source and target.