Skip to content

Instantly share code, notes, and snippets.

@Daksh
Created August 7, 2020 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daksh/76a7647350e69d59a220ca019191abf2 to your computer and use it in GitHub Desktop.
Save Daksh/76a7647350e69d59a220ca019191abf2 to your computer and use it in GitHub Desktop.
Prison Cells After N Days
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