Code RoomSensor firmware propagation
EasyPrep Room Coding #4844

Sensor firmware propagation

CodingAlgorithms & data structuresEntry–Mid~17 min

A factory covers its floor with a mesh of sensor nodes laid out on a rectangular grid, one cell per position. A cell holds '.' for a node and '#' for a steel press, which blocks radio outright. A firmware update starts at the gateway node at gateway_row and gateway_col and travels in hops: on each hop every node that already holds the update passes it to the nodes sharing an edge, never diagonally and never through a press. A node takes the update on the earliest hop that reaches it and never again. Return a list of length hops plus 1 where the entry at index d is how many nodes first receive the update on hop d, so index 0 counts the gateway itself. Return that list filled with zeros when the grid has no cells, when the gateway sits outside it, or when the gateway sits on a press. hops is never negative, and every row has the same width.

Implement
mesh_hop_counts(layout: list[list[str]], gateway_row: int, gateway_col: int, hops: int) → list[int]
Examples
in[[[".",".","."],[".","#","."],[".",".","."]],0,0,2]out[1,2,2]
in[[[".","#"],["#","."]],0,0,3]out[1,0,0,0]
in[[[".",".",".",".","."]],0,2,3]out[1,2,2,0]
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 17 min
InputExpectedGot
[[[".",".","."],[".","#","."],[".",".","."]],0,0,2][1,2,2]not run yetsample
[[[".","#"],["#","."]],0,0,3][1,0,0,0]not run yetsample
[[[".",".",".",".","."]],0,2,3][1,2,2,0]not run yetsample