Game of Life: Next Generation
Updated
Problem statement
Given a rectangular grid board of dead cells (0) and live cells (1), return its state after one simultaneous Game of Life generation.
Each cell has up to eight neighbors: horizontal, vertical, and diagonal cells within the grid. A live cell survives with two or three live neighbors and otherwise dies. A dead cell becomes live with exactly three live neighbors and otherwise stays dead. Count all neighbors from the original grid before any update.
For this exercise, the grid is finite: cells outside it are dead. Return the complete next-state grid in the same dimensions.
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]]Apply the neighbor counts to the original four-row grid at the same time.
Example 2
board = [[1,1],[1,0]]return = [[1,1],[1,1]]The dead lower-right cell has three live neighbors and becomes live; the others each have two neighbors and survive.
Example 3
board = [[0,0,0],[1,1,1],[0,0,0]]return = [[0,1,0],[0,1,0],[0,1,0]]The three-cell horizontal line becomes a vertical line because updates occur simultaneously.
Constraints
1 <= board.length, board[i].length <= 25.- Every row has the same length.
- Every cell is
0or1.
More Meta Onsite Interview questions
- Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Linear Layer Forward and Backward PassesONSITE INTERVIEW · Seen Sep 2026
- Reservoir Sampling with Recorded DrawsONSITE INTERVIEW · Seen Sep 2026
- Stochastic Gradient Descent with MomentumONSITE INTERVIEW · Seen Sep 2026
- Top K Largest Values with a HeapONSITE INTERVIEW · Seen Sep 2026
- Partition a Card Deck into FifteensONSITE INTERVIEW · Seen Sep 2026
- Insert into a Sorted Circular ListONSITE INTERVIEW · Seen Aug 2026
Similar questions at other companies
- Random Bingo Card GeneratorUber · ONSITE INTERVIEWUber interview questions
- Rectangle Point Coverage CountsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Spiral MatrixAthenahealth · ONSITE INTERVIEW
- Explore an Unknown Grid and Find a PathLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Spiral MatrixNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
- Tic-Tac-Toe Move WinnersByteDance · ONSITE INTERVIEWByteDance interview questions
- Trace Every Water Drop to Its Resting DestinationGoogle · ONSITE INTERVIEWGoogle interview questions
- Cyclic Fuel Command SimulationWaymo · ONSITE INTERVIEWWaymo interview questions
- Generate a Spiral MatrixMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Spiral Matrix with ObstaclesTemu · ONSITE INTERVIEWTemu interview questions
Meta interview experiences
- Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
- Meta Business Support Engineer Phone Screen: 1 Experience
- Meta Software Engineer Onsite Questions: 3 Experiences
- Meta AI Native Engineer OA and Onsite: 1 Experience
- Meta AI-Native Coding Interview: 3 Experiences
- Meta Production Engineer Intern Questions: 6 Experiences