Plant Poison Spread
Asked at Apple· Screen
Reported by the problem's creator, not verified
A field of plants is an m x n grid. 0 is a healthy plant and 1 is a poisoned one. The neighbors of a plant are the up to 8 plants around it, horizontally, vertically and diagonally; plants on an edge or in a corner have fewer.
Each day, every healthy plant with at least k poisoned neighbors becomes poisoned. All plants change at the same moment: what happens on a day depends only on the field as it was at the start of that day. A plant that turns poisoned on a day counts as a poisoned neighbor from the next day on. Poisoned plants stay poisoned.
Examples
Example 1
Input: grid =
[[0,1,1,0],[0,0,0,0],[0,0,0,0]], k =2Output:
3Explanation: On day 1 the two cells under the poisoned pair each touch two poisoned plants, so they turn. On day 2 the top corners, the left and right cells of the middle row and the two bottom-middle cells each touch two poisoned plants. On day 3 the bottom corners touch three. After that nothing changes, so the answer is 3.