Game of Life
MediumBit Manipulation & Math
Decode it first. Clues, constraints, pattern and plan before any code.A grid board of m rows and n columns holds cells that are alive (1) or dead (0). Each cell has up to eight neighbours: the cells touching it horizontally, vertically and diagonally. The next generation follows two rules:
- A live cell with two or three live neighbours stays alive; any other live cell dies.
- A dead cell with exactly three live neighbours comes alive; any other dead cell stays dead.
Every cell changes at the same moment, so each cell's fate depends only on the current generation. Update board to the next generation in place. The function returns nothing; the tests inspect board after the call.
[[0, 1, 0], [[0, 0, 0],
[0, 1, 0], → [1, 1, 1],
[0, 1, 0]] [0, 0, 0]]
[[0, 1], [[1, 1],
[1, 1]] → [1, 1]]Constraints
1 <= m, n <= 25board[i][j]is0or1.