Skip to main content
Medium Matrix Medium frequency

Game of Life

Open on LeetCode

Approach Summary

Encode intermediate states in-place using extra values (e.g. 2 = was live, now dead). Two-pass: first encode transitions, then finalise.

How to Recognize This Pattern

  • In-place update without auxiliary matrix
  • Intermediate state encoding avoids O(m*n) extra space

Complexity Analysis

Time Complexity

O(m × n)

Space Complexity

O(1)

Tags

Array Matrix Simulation

This site is free. If these guides are helping your prep, consider buying me a coffee. ☕

Support →
Buy me a coffee