This question evaluates a candidate's ability to model and simulate dynamic grid processes, reason about infection propagation and delayed state changes, and incorporate constrained intervention decisions.
You are given an m x n grid representing a garden:
0
: empty cell
1
: healthy plant
2
: infected plant
The garden evolves day by day in the following order:
K
orthogonally adjacent infected neighbors at the end of a day, it becomes marked for death.
D
days after the first day it was marked, and the cell becomes empty.
Assume that once a plant is marked, its death timer does not reset. Dead or burned cells do not spread infection, cannot be infected again, and are not counted as infected neighbors.
Answer both parts:
K
, and
D
, compute how many plants eventually die because of the overcrowding rule.