Game of Life

Compute the next state (in-place) of Conway’s Game of Life on an `m x n` board. Use in-place marking (e.g. state encoding) to avoid extra memory. Each cell’s next state depends on its live neighbors (8 directions).

Input Format

2D list of 0/1 ints.

Output Format

Modified board.

Constraints

  • m,n ≤ 25.

Examples

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:

Standard Game of Life transition.

Loading...
Game of Life - Matrix DSA Problem