Advance a Binary Life Board Simultaneously In Place

Quick Overview

Advance a Binary Life Board Simultaneously In Place. Apply one Game of Life generation to board. Each cell has up to eight surrounding neighbors. A live cell survives with two or three live neighbors and otherwise

Advance a Binary Life Board Simultaneously In Place

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Apply one Game of Life generation to board. Each cell has up to eight surrounding neighbors. A live cell survives with two or three live neighbors and otherwise dies; a dead cell becomes live with exactly three. All changes use the old generation simultaneously. The original API returns void and mutates board. ```cpp void gameOfLife(vector<vector<int>>& board); ``` ### Examples ```text board = [[0,1,0],[0,1,0],[0,1,0]] -> [[0,0,0],[1,1,1],[0,0,0]] board = [[1]] -> [[0]] ``` ### Constraints - Both dimensions are in [1,25]. - Entries are integer 0 or 1. ### Optional follow-up Can updates be in place despite simultaneity? How would an infinite board change representation and boundary handling?

Overview: Advance a Binary Life Board Simultaneously In Place. Apply one Game of Life generation to board. Each cell has up to eight surrounding neighbors. A live cell survives with two or three live neighbors and otherwise

Amazon logo
Amazon
Date not reported
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Apply one Game of Life generation to board. Each cell has up to eight surrounding neighbors. A live cell survives with two or three live neighbors and otherwise dies; a dead cell becomes live with exactly three. All changes use the old generation simultaneously. The original API returns void and mutates board.

void gameOfLife(vector<vector<int>>& board);

Examples

board = [[0,1,0],[0,1,0],[0,1,0]] -> [[0,0,0],[1,1,1],[0,0,0]]
board = [[1]] -> [[0]]

Constraints

  • Both dimensions are in [1,25].
  • Entries are integer 0 or 1.

Optional follow-up

Can updates be in place despite simultaneity? How would an infinite board change representation and boundary handling?