Created
August 7, 2020 20:47
-
-
Save Daksh/76a7647350e69d59a220ca019191abf2 to your computer and use it in GitHub Desktop.
Prison Cells After N Days
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def prisonAfterNDays(self, cells: List[int], N: int) -> List[int]: | |
memory = {} | |
for it in range(N): | |
ocells = cells[:] | |
for i in range(1,7): | |
if ocells[i-1]==ocells[i+1]: | |
cells[i] = 1 | |
else: | |
cells[i] = 0 | |
cells[0], cells[-1] = 0, 0 | |
if memory and memory[0]==cells: | |
break | |
memory[it] = cells[:] | |
rep = len(memory) | |
return memory[(N-1)%rep] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment