Trains the technique from
LeetCode 994Rotting OrangesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A storage aisle is wired as a rectangular grid racks. Every cell carries one of three codes:
0 marks an empty bay,1 marks a node running healthy firmware,2 marks a node whose firmware is already corrupted.Corruption travels on a fixed clock. During each tick, every healthy node that shares an edge with a node corrupted before that tick becomes corrupted itself. Empty bays carry nothing, and cells touching only at a corner are not neighbours.
Return how many ticks pass before nothing healthy is left in the aisle. If some healthy node can never be reached, return -1 instead.
Example 1
The four edge neighbours of the corrupted middle go in tick 1, and the two remaining corner nodes go in tick 2.
Example 2
The empty bay sits between the two nodes, so the healthy one on the right is never touched.
Example 3
No healthy node is present when the clock starts, so the aisle is already settled.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def infection_ticks(racks: list[list[int]]) -> int:public int infectionTicks(int[][] racks)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.