18/32
Part 5 of 7 · RoundsLearn and do

Simulate in rounds when the rule goes beyond distance

When a tree needs k burning neighbors, the minute it catches is no longer its distance

Here's a forest where a tree catches only when at least k = 2 of its neighbors are burning:

k = 2: a tree catches when two neighbors burn
minute 0
F.F...F..
minute 1
FFFF..F..
minute 2
FFFFF.F..
minute 3
FFFFFFFF.
minute 4
FFFFFFFFF

The bottom-right tree is 2 steps from the nearest fire. It catches at minute 4, once two of its neighbors are burning. A BFS would say 2.

BFS fits when one burning neighbor is enough and a fire burns forever. Interview spreads add rules: a tree catches only when at least k of its neighbors burn, a fire burns out, an infected cell recovers. Then the minute a cell catches is no longer its distance from a source.

In the editor, write burning_neighbors(grid, r, c), how many of a cell's neighbors are F. Then write catches(grid, r, c, k), whether a tree catches this minute. K2 is the k = 2 forest above.