Description

Apply Game of Life rules to a board in-place. Live cell with 2-3 neighbors survives, dead cell with 3 neighbors becomes live.

Examples

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:

Next state after applying rules.

Input:board = [[1]]
Output:[1]
Explanation:

Minimal case with a single-element matrix.

Input:board = [[1,1,0,0],[1,0,1,0],[0,1,0,1],[0,0,1,1]]
Output:[[1,1,0,0],[1,0,0,0],[0,0,0,1],[0,1,1,1]]
Explanation:

A 4x4 board demonstrating various Game of Life scenarios: live cells at (0,0) and (0,1) survive with 2-3 neighbors, cell at (1,1) dies from underpopulation (only 1 neighbor), cell at (2,1) dies from isolation, and dead cell at (3,1) becomes alive with exactly 3 neighbors.

Constraints

  • 1 ≤ m, n ≤ 25
  • board[i][j] is 0 or 1

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!