Back to problems

Plant Infection Spread: Days Until Stable

Algorithm · Apple · Medium

You are given an m x n grid in which 0 marks a healthy plant and 1 marks an infected plant, along with an integer threshold K. The infection spreads in daily steps: on each day, every healthy cell that is surrounded by at least K infected cells, counting all 8 adjacent positions (horizontal, vertical, and diagonal), becomes infected. Return the number of days it takes for the grid to reach a stable state, meaning the first day on which no additional cell becomes infected.…

Loading the rest of the question…