FastPrepGame of Life: In-Place Next Generation
Problems/Game of Life: In-Place Next Generation

Game of Life: In-Place Next Generation

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names a well-known Game of Life problem and adds a follow-up to change the board in place. We took the standard Game of Life rules from that problem. The function returns the changed board, so it can be checked exactly. Our version is about 95% the same as the reported question.

Given a finite rectangular binary grid board, compute one simultaneous generation of Conway's Game of Life.

  • A live cell with two or three live neighbors survives.
  • A dead cell with exactly three live neighbors becomes live.
  • Every other cell is dead in the next generation.

Each cell has up to eight horizontal, vertical, and diagonal neighbors. Cells outside the grid are dead. Every decision must use the original generation.

Modify the supplied board in place and return it. You may encode temporary old/new state in each cell, but you must not allocate another grid proportional to the board size.

Function

gameOfLife(board: int[][]) → int[][]

Examples

Example 1

board = [[0,1,0],[0,0,1],[1,1,1],[0,0,0]]return = [[0,0,0],[1,0,1],[0,1,1],[0,1,0]]
board
0120010100121113000
→
return
0120000110120113010
Moved or new

Neighbor counts come from the original four-row grid, so all births and deaths occur simultaneously.

Example 2

board = [[1,1],[1,0]]return = [[1,1],[1,1]]
board
01011110
→
return
01011111
Moved or new

The dead corner has three live neighbors and is born; each original live cell has two neighbors and survives.

Example 3

board = [[0,0,0],[1,1,1],[0,0,0]]return = [[0,1,0],[0,1,0],[0,1,0]]
board
012000011112000
→
return
012001010102010
Moved or new

The horizontal blinker becomes vertical when every cell reads the same original generation.

Constraints

  • 1 <= board.length, board[r].length <= 200.
  • Every row has equal length and every cell is 0 or 1.
  • The update must use O(1) auxiliary space beyond the returned board.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Spiral MatrixAthenahealth · ONSITE INTERVIEW
  • Spiral MatrixNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
  • Incremental Hard Attention with a KV CacheOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Stochastic Gradient Descent with MomentumMeta · ONSITE INTERVIEWMeta interview questions
  • Minesweeper Board UpdateUber · ONSITE INTERVIEWUber interview questions
  • 2048 Simulation and Board CodecCitadel · ONSITE INTERVIEWCitadel interview questions
  • Diagonal Matrix IteratorMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Candy Crush Board Until StableBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Game of Life Next GenerationTemporal · ONSITE INTERVIEWTemporal interview questions
  • Minesweeper Board UpdateClay · ONSITE INTERVIEW

Interview reports that mention this question

  • Google New Grad SWE R2 Coding Questions: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[][] gameOfLife(int[][] board) {
        // write your code here
    }
}
Checking account…