Game of Life
Given a board of 0s and 1s, return the next state according to Conway's Game of Life rules.
Examples
Input: [[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]]
Input: [[1,1],[1,0]]
Output: [[1,1],[1,1]]
Hints
Use a temporary board to store the next state while calculating live neighbors to avoid overwriting the current state prematurely.
Implement boundary checks to handle edge cells (corners and borders) where neighbor counts may differ due to fewer adjacent cells.
Optimize neighbor counting by iterating through all 8 possible directions (including diagonals) for each cell while ensuring no out-of-bounds access.
Related Problems
Game of Life
Given a board of 0s and 1s, return the next state according to Conway's Game of Life rules.