Tap here to switch tabs
Problem
Submissions

Problem: Prison Cells After N Days

med
30 min
Try to solve the Prison Cells After N Days problem.

Statement

There are 88 prison cells arranged in a row, where each cell is represented by either 11 if it is occupied or 00 if it is vacant.

Every day, the state of all cells changes simultaneously based on these rules:

  • A cell becomes occupied with a value of 11 if both of its adjacent neighbors are occupied or both are vacant.

  • Otherwise, the cell becomes vacant with a value of 00.

Since the first and last cells in the row lack two adjacent neighbors, they cannot satisfy the condition and become vacant with a value of 00 on each subsequent day.

Given an integer array cells representing the initial state of the prison and an integer n, return the state of the prison cells after n days.

Constraints:

  • cells.length is equal to 88

  • cells[i] is either 00 or 11

  • 1≤n≤1091 \le n \le 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Prison Cells After N Days

med
30 min
Try to solve the Prison Cells After N Days problem.

Statement

There are 88 prison cells arranged in a row, where each cell is represented by either 11 if it is occupied or 00 if it is vacant.

Every day, the state of all cells changes simultaneously based on these rules:

  • A cell becomes occupied with a value of 11 if both of its adjacent neighbors are occupied or both are vacant.

  • Otherwise, the cell becomes vacant with a value of 00.

Since the first and last cells in the row lack two adjacent neighbors, they cannot satisfy the condition and become vacant with a value of 00 on each subsequent day.

Given an integer array cells representing the initial state of the prison and an integer n, return the state of the prison cells after n days.

Constraints:

  • cells.length is equal to 88

  • cells[i] is either 00 or 11

  • 1≤n≤1091 \le n \le 10^9