Advance a Grid of Online Status Cells by One Generation In Place
Last updated: November 29, 2026
Quick Overview
Simulate one step of Conway's Game of Life on an m x n board of 0s and 1s, framed as a toy model of friends going online when enough neighbors are active. Update the board in place.
Meta
November 29, 20260
0
0 solved
Simulate one step of Conway's Game of Life on an m x n board of 0s and 1s, framed as a toy model of friends going online when enough neighbors are active. Update the board in place.
A Meta onsite simulation question where the trap is that updates must use the old state of every neighbor. Interviewers look for in-place encoding of old and new states, and then push on infinite boards and scale.
What the Interviewer Expects
- Apply the four Life rules correctly
- Explain why naive in-place updates corrupt neighbor counts
- Encode old and new state in two bits of each cell
- Finalize with a second pass shift
- Discuss sparse representations for huge or infinite boards
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you handle an unbounded board?
- How would you distribute this across machines for a 10^6 x 10^6 board?
- Only a few cells change each step. How do you avoid scanning the whole board?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: m x n grid of 0 (offline) and 1 (online). Rules for each cell, counting its 8 neighbors: live with < 2 live neighbors dies; live with 2 or 3 lives; live with > 3 dies; dead with exactly 3 becom...
High-Level Design
Updating a cell immediately would change its neighbors' counts later in the scan. Instead store both generations in one integer: bit 0 is the current state, bit 1 the next state.
Pass 1: for each cel...