FastPrepGame of Life on a Finite and an Infinite Board
Problems/Game of Life on a Finite and an Infinite Board

Game of Life on a Finite and an Infinite Board

Citadel logoCitadel● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Seen in one Citadel Securities account, posted in March 2026, from an experienced engineer applying for a full-time software job. In the second of two phone interviews, the candidate had to compute the next generation of a Game of Life board in place, a well-known practice problem. Follow-up questions asked what changes for a very large board (1000 by 1000), for a board where nearly all cells are dead, and for a board without edges. The account does not say what answers the interviewer was looking for.

We kept 1000 as the largest board side. The function returns the updated board so it can be checked. We turned the follow-ups into a second part: the board has no edges, you get only the live cells as coordinates, and you return the next generation's live cells sorted by row, then by column. One function with a flag answers both parts. The limits of the second part (up to 10^4 live cells, coordinates up to 10^9 either way) and all examples are ours. The memory question for a large board is covered in the editorial, not in the tests.

Our version is about 75% the same as the reported question.

In the Game of Life, a board is a grid of cells. Each cell is either live (1) or dead (0). A cell's neighbors are the eight cells next to it: horizontally, vertically and diagonally. All cells change at the same moment to form the next generation:

  • A live cell with fewer than two live neighbors dies.
  • A live cell with two or three live neighbors stays live.
  • A live cell with more than three live neighbors dies.
  • A dead cell with exactly three live neighbors becomes live.

The problem comes in two parts, and one function answers both. The flag infinite tells you which part a call belongs to.

  1. Part 1 (infinite = false): board is an m x n grid of 0 and 1 values. Cells outside the grid count as dead. Update board in place to the next generation, using only constant extra memory, and return it.
  2. Part 2 (infinite = true): the board has no edges and goes on forever in every direction, and almost every cell is dead. Now board lists the live cells, each as a pair [row, col]. Every cell not in the list is dead. Return the live cells of the next generation as [row, col] pairs, sorted by row and then by column. A new live cell may lie just outside the range of the input coordinates. If no cell is live, return an empty list.

Function

gameOfLife(board: int[][], infinite: boolean) → int[][]

Examples

Example 1

board = [[0,1,0,0],[0,0,1,0],[1,1,1,0],[0,0,0,0]]infinite = falsereturn = [[0,0,0,0],[1,0,1,0],[0,1,1,0],[0,1,0,0]]
board
012300100100102111030000
→
return
012300000110102011030100
Moved or new

Part 1. Cells (0, 1) and (2, 0) each have one live neighbor, so they die. Cell (1, 2) has three live neighbors and stays live, and (2, 2) has two and stays live too. (2, 1) has three and stays live. The dead cells (1, 0) and (3, 1) each have three live neighbors, so they become live. The function changes board and returns it.

Example 2

board = [[-1,0],[0,0],[1,0]]infinite = truereturn = [[0,-1],[0,0],[0,1]]
board
010-10100210
→
return
0100-1100201
Moved or new

Part 2. The live cells form a short vertical line. The middle cell (0, 0) has two live neighbors and stays live. The two end cells have one each and die. The dead cells (0, -1) and (0, 1) each touch all three live cells, so they become live. The line turns sideways.

Example 3

board = [[1000000000,-1000000000],[5,5],[5,6],[6,5]]infinite = truereturn = [[5,5],[5,6],[6,5],[6,6]]

Part 2. The first cell is far from the others and has no live neighbors, so it dies. Each of the other three cells has two live neighbors and stays live. The dead cell (6, 6) has three live neighbors, so it becomes live. The answer is sorted by row, then by column.

Constraints

  • Part 1: m == board.length and n == board[i].length
  • Part 1: 1 <= m, n <= 1000
  • Part 1: board[i][j] is 0 or 1
  • Part 2: 1 <= board.length <= 104
  • Part 2: board[i].length == 2
  • Part 2: -109 <= board[i][0], board[i][1] <= 109
  • Part 2: all board[i] are distinct

More Citadel Phone Screen questions

  • Speed Up a Slow FunctionOA · PHONE SCREEN · Seen Nov 2026
  • Portfolio Tickers with Constant-Time Random PickPHONE SCREEN · Seen Nov 2026
  • Square Root FunctionPHONE SCREEN · Seen Oct 2026
  • Reachable Transfer PositionsPHONE SCREEN · Seen Oct 2026
  • Spreadsheet Formula DependenciesPHONE SCREEN · Seen Oct 2026
  • Currency Arbitrage CyclePHONE SCREEN · Seen Sep 2026
  • Order Book with Cancel by Order IDPHONE SCREEN · Seen Sep 2026
  • Smart Queue of Latest PricesPHONE SCREEN · Seen Sep 2026
  • Merge Price-Delta FeedsPHONE SCREEN · Seen Sep 2026
  • Reconcile Unmatched Trades with Timestamp TolerancePHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • First Completed Mingo LineEpic · OAEpic interview questions
  • Cache Shared Image Pipeline PrefixesAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Logger Rate Limiter with Every-Arrival HistoryGoogle · PHONE SCREENGoogle interview questions
  • Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
  • Order and Batch Open-Close LifecycleHudson River Trading · PHONE SCREENHudson River Trading interview questions
  • Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
  • Rectangle Point Coverage CountsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Resource Reconciler: Plan and Apply CreatesPerplexity AI · PHONE SCREENPerplexity AI interview questions
  • Realized Gains from a Real-Estate Transaction StreamKikoff · PHONE SCREENKikoff interview questions

Citadel interview experiences

  • Citadel Securities Quant Researcher Intern Loop: 1 Experience
  • Citadel Securities Research Engineer Interview: 1 Experience
  • Citadel Securities SWE Intern First Round: 2 Experiences
  • Citadel Securities Experienced SWE Interviews: 1 Experience
  • Citadel SWE Intern Later Rounds and Superday: 13 Experiences
  • Citadel SWE Intern First-Round Questions: 20 Experiences
All Citadel interview questionsSee Citadel hiring insights
Saved
class Solution {
    public int[][] gameOfLife(int[][] board, boolean infinite) {
      // Write your code here.
    }
}
Checking account…