At GenCell Labs, researchers use a simplified cellular model on a 2D grid. Each cell is either active (1) or inactive (0). For each simulation step, every cell updates simultaneously using the number of active neighbors in the 8 surrounding positions.
Implement a function that returns the grid after exactly steps updates using these rules:
2 or 3 active neighbors; otherwise it becomes inactive.3 active neighbors; otherwise it stays inactive.grid as a list of lists of integers (0 or 1), and integer steps >= 0steps timesExample 1
Input: grid = [[0,1,0],[0,1,0],[0,1,0]], steps = 1
Output: [[0,0,0],[1,1,1],[0,0,0]]
Explanation: The vertical line becomes a horizontal line after one simultaneous update.
Example 2
Input: grid = [[1,1],[1,1]], steps = 2
Output: [[1,1],[1,1]]
Explanation: Each cell has exactly 3 active neighbors, so the 2x2 block remains stable.
1 <= rows, cols <= 500 <= steps <= 100grid[i][j] is either 0 or 1