Update a 2D board one generation at a time using the rules of Conway's Game of Life.
You are given an board where each cell is either alive (1) or dead (0). The board evolves in discrete steps according to the following rules:
A cell's neighbors are the 8 surrounding cells horizontally, vertically, and diagonally adjacent.
Modify the board in place to represent the next generation.
board of size m x n.board[i][j] = 1 means the cell is alive, and 0 means it is dead.board in place so that it reflects the next state of the grid.1 <= m, nExample 1
Input
board = [[0,1,0],[0,0,1],[1,1,1],[0,0,0]]
Output
[[0,0,0],[1,0,1],[0,1,1],[0,1,0]]
Explanation
Apply the four rules to every cell simultaneously using the original board state. The resulting next generation is shown in the output.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.