Free written solutionPrison Cells After N Days (LeetCode 957): Solution and Explanation
Eight cells change every day: a cell becomes occupied when its two neighbors match and vacant otherwise, and the end cells always empty. Return the cells after n days, where n can be a billion. With cells = [0,1,0,1,1,0,0,1] and n = 7 the answer is [0,0,1,1,0,0,0,0].
Read the intuition, approach, code and complexity →