Game of Life
According to the rules of Conway's Game of Life, each cell in a board is either live or dead. Given the current state of the board, update the board to its next state.
The next state of each cell depends on its eight neighboring cells:
- A live cell with fewer than two live neighbors dies.
- A live cell with two or three live neighbors survives.
- A live cell with more than three live neighbors dies.
- A dead cell with exactly three live neighbors becomes alive.
Update the board in-place.
Example 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
Each cell is updated according to the number of live neighbors it has. The complete board changes simultaneously to its next generation.
Example 2
Input
board = [[1,1],
[1,0]]Output
[[1,1], [1,1]]
Explanation
The dead cell has exactly three live neighbors, so it becomes alive. The other cells continue to satisfy the survival rules.
Constraints
Hints:
Hint 1
For every cell, count the number of live cells among its eight neighboring positions.
Hint 2
To update the board in-place, use temporary state values to represent cells that are changing while preserving their original state.
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Aug 18, 2026
Last updated
Aug 18, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output