Advance a Cellular Automaton Grid One Generation In Place
Last updated: November 29, 2026
Quick Overview
Given a grid of live (1) and dead (0) cells following Conway's rules (live cells survive with 2 or 3 live neighbors, dead cells become live with exactly 3), compute the next generation in place without allocating a second grid.
Microsoft
November 29, 20260
0
0 solved
Given a grid of live (1) and dead (0) cells following Conway's rules (live cells survive with 2 or 3 live neighbors, dead cells become live with exactly 3), compute the next generation in place without allocating a second grid.
Microsoft interviewers use the Game of Life to probe in-place state encoding, a skill that matters for memory conscious code in Windows and Xbox. They watch whether you read only original states while writing next states.
What the Interviewer Expects
- Apply the rules using all eight neighbors
- Encode the next state in a second bit so original values remain readable
- Finalize with a right shift pass
- Handle borders without wrapping
- Discuss infinite boards and sparse representations
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 infinite board?
- How would you parallelize across many cores or a GPU?
- What if the board wraps around at the edges?
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: grid of 0 and 1 values.
- All cells update simultaneously from the current generation.
- Neighbors are the eight surrounding cells within bounds.
- Update in place, O(1) extra memory....
High-Level Design
A naive in-place update breaks simultaneity: once a cell changes, its neighbors would read the new value. Use two bits per cell. Bit 0 holds the current state and is never modified during the counting...