Game of Life
Given an m x n board of cells that are live (1) or dead (0), compute the next state under Conway's Game of Life rules applied simultaneously to every cell, and update the board in place.
Open official problem prompt ↗Advance the whole grid one generation of Conway's Game of Life at once, without a second board.
Like everyone in a stadium deciding to stand or sit at the same signal based on their current neighbors; you must read everyone's present pose before anyone moves.
- 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]]
- Why
- Each cell's next value depends only on its eight neighbors in the original board; applying the survival/birth rules everywhere at once yields this grid.
m == board.lengthn == board[i].length1 <= m, n <= 25board[i][j] is 0 or 1