I am working on 957. Prison Cells After N Days but getting timeout error for my code. as I assume my code should be 14+O(n-14) about O(n) am I right since after 14 run pattern will be repeated? and how can I improve my code?
from collections import defaultdict step_map = defaultdict(list) for k in range(N): if tuple(cells) in step_map: cells = step_map[tuple(cells)] else: tmp = list() for i in range(1, 7): tmp += [int(cells[i - 1] == cells[i + 1])] tmp =  + tmp +  step_map[tuple(cells)] = tmp cells = tmp return cells