Blight Spread Days
MediumSimulation · Apple
Given a grid beds where 1 is a blighted plant and 0 is a healthy one, and an integer k, return the number of days on which at least one plant becomes blighted.
Each day, every healthy plant with at least k blighted plants among its up to 8 surrounding cells (diagonals included) becomes blighted. All plants change at once, based on the grid at the start of that day. Blighted plants stay blighted.
Example 1
- Input:
- beds = [[1, 1, 0], [0, 0, 0], [0, 0, 0]], k = 2
- Output:
- 3
- Explanation
- Day 1 blights the two cells under the pair, day 2 the four cells that then touch two blighted cells, day 3 the last corner.
Example 2
- Input:
- beds = [[1, 0], [0, 0]], k = 2
- Output:
- 0
Example 3
- Input:
- beds = [[1, 0], [0, 1]], k = 2
- Output:
- 1
- Explanation
- Each healthy cell touches both blighted cells diagonally.
Constraints
- 1 ≤
beds.length,beds[0].length ≤ 100 beds[i][j] is0or1- 1 ≤
k≤ 8