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
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

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
matrix
bit manipulation
in-place
simulation
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported