|
| 1 | + |
| 2 | +# Prison Cells After N Days |
| 3 | +[Leetcode Link](https://leetcode.com/problems/prison-cells-after-n-days/) |
| 4 | + |
| 5 | +## Problem: |
| 6 | + |
| 7 | +There are 8 prison cells in a row, and each cell is either occupied or vacant. |
| 8 | + |
| 9 | +Each day, whether the cell is occupied or vacant changes according to the following rules: |
| 10 | + |
| 11 | +If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied. |
| 12 | +Otherwise, it becomes vacant. |
| 13 | +(Note that because the prison is a row, the first and the last cells in the row can't have two adjacent neighbors.) |
| 14 | + |
| 15 | +We describe the current state of the prison in the following way: `cells[i] == 1` if the `i`-th cell is occupied, else `cells[i] == 0`. |
| 16 | + |
| 17 | +Given the initial state of the prison, return the state of the prison after `N` days (and `N` such changes described above.) |
| 18 | + |
| 19 | +## Example: |
| 20 | + |
| 21 | +``` |
| 22 | +Input: cells = [0,1,0,1,1,0,0,1], N = 7 |
| 23 | +Output: [0,0,1,1,0,0,0,0] |
| 24 | +Explanation: |
| 25 | +The following table summarizes the state of the prison on each day: |
| 26 | +Day 0: [0, 1, 0, 1, 1, 0, 0, 1] |
| 27 | +Day 1: [0, 1, 1, 0, 0, 0, 0, 0] |
| 28 | +Day 2: [0, 0, 0, 0, 1, 1, 1, 0] |
| 29 | +Day 3: [0, 1, 1, 0, 0, 1, 0, 0] |
| 30 | +Day 4: [0, 0, 0, 0, 0, 1, 0, 0] |
| 31 | +Day 5: [0, 1, 1, 1, 0, 1, 0, 0] |
| 32 | +Day 6: [0, 0, 1, 0, 1, 1, 0, 0] |
| 33 | +Day 7: [0, 0, 1, 1, 0, 0, 0, 0] |
| 34 | +``` |
| 35 | +``` |
| 36 | +Input: cells = [1,0,0,1,0,0,1,0], N = 1000000000 |
| 37 | +Output: [0,0,1,1,1,1,1,0] |
| 38 | +``` |
| 39 | + |
| 40 | +## Note: |
| 41 | + |
| 42 | +1. `cells.length == 8` |
| 43 | +2. `cells[i]` is in `{0, 1}` |
| 44 | +3. `1 <= N <= 10^9` |
0 commit comments