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 1grid = [[0,1,0],[0,1,0],[0,1,0]], steps = 1Output[[0,0,0],[1,1,1],[0,0,0]]WhyThe middle column has three active cells. After one simultaneous update, it becomes a horizontal line in the middle row.grid = [[1,1],[1,1]], steps = 2Output[[1,1],[1,1]]WhyEvery cell has exactly three active neighbors, so the block remains unchanged across both steps.grid = [[1]], steps = 1Output[[0]]WhyA single active cell has no active neighbors, so it becomes inactive.1 <= len(grid) <= 501 <= len(grid[0]) <= 500 <= steps <= 100grid[i][j] is either 0 or 1All cells update simultaneously within each stepdef evolve_cells(grid, steps):