Code RoomRelay activation time
MediumPrep Room Coding #62

Relay activation time

CodingAlgorithms & data structuresMid–Senior~30 min

A grid of size m x n holds values: 0 = empty, 1 = a fresh resource, 2 = an active relay. Each minute, every active relay activates all empty cells that are 4-directionally adjacent to it, turning them into relays (value 2). Fresh resources (1) are obstacles and are never activated and never block; they simply stay 1. Return the number of minutes until there are no more empty (0) cells reachable from any relay, i.e. the last minute at which any empty cell becomes a relay. If there are no empty cells at all, return 0. Cells that remain unreachable empty after the process make this impossible — return -1 in that case.

Implement
relay_spread(grid: list[list[int]]) → int
Examples
in[[[2,0,1],[0,0,1],[1,0,0]]]out4
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 30 min
InputExpectedGot
[[[2,0,1],[0,0,1],[1,0,0]]]4not run yetsample