Trains the technique from
LeetCode 2385Amount of Time for Binary Tree to Be InfectedThis 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 rack of relays is wired as a binary tree. The wiring arrives as layout, the level-order
walk of that tree: layout[0] is the root relay, and the walk then lists the left and right
child slot of every relay it has already listed, in the same order, writing null for a slot
with no relay in it. A null slot has no child slots of its own, and trailing null entries
are left off the end. Every relay carries a different label.
A firmware update is loaded onto the relay labelled seed. Each wire joins a relay to a
child and carries the update in either direction. During one minute, every relay that
already holds the update pushes it across all of its wires, so each neighbouring relay
without the update picks it up.
Return the number of minutes until every relay in the rack holds the update. A rack of one
relay is already done, so the answer is 0.
Example 1
Minute 1 puts the update on relays 1, 3 and 4. Minute 2 puts it on relay 9, and minute 3 puts it on relay 7, which is the last relay in the rack.
Example 2
The update spreads to relays 3, 4 and 7 in minute 1, to 1 and 8 in minute 2, to 10 in minute 3, to 14 in minute 4 and to 13 in minute 5.
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 cascade_minutes(layout: list[int | None], seed: int) -> int:public int cascadeMinutes(Integer[] layout, int seed)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.