Skip to content

Practice Prison Cells After N Days

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#957
LeetCode Problem

Prison Cells After N Days

Problem Statement

Eight cells form a row, with 1 occupied and 0 vacant. Update every cell simultaneously each day: an interior cell becomes occupied exactly when its two neighbors were both occupied or both vacant; otherwise it becomes vacant. End cells lack two neighbors and become vacant. Return the state after n updates.

Source: Prison Cells After N Days on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
cells = [0,1,0,1,1,0,0,1], n = 7
Output
[0,0,1,1,0,0,0,0]

# Example 2

Input
cells = [1,0,0,1,0,0,1,0], n = 1000000000
Output
[0,0,1,1,1,1,1,0]

Constraints

cells.length == 8
cells[i] is either 0 or 1.
1 <= n <= 10^9

Related LeetCode Problems

Practice more problems similar to Prison Cells After N Days.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.