lamps describes them today: lamps[i] = 1 if lamp i is lit and 0 if it is not.
Every night all lamps change at the same time according to this rule:
- if a lamp has two neighbours and they are both lit or both dark, it becomes lit;
- otherwise it goes dark.
The two end lamps have only one neighbour each, so from the first night on they are always dark.
Return the state of the lamps after nights nights.lamps=[1, 0, 0, 1, 1, 1, 0, 1], nights=1 → [0, 0, 0, 0, 1, 0, 1, 0]
The end lamps go dark. Lamp 1 has neighbours 1 and 0, which differ, so it goes dark; lamp 2 has 0 and 1, dark too; lamp 4 has 1 and 1, so it is lit; and so on.
lamps=[0, 0, 0, 0, 0, 0, 0, 0], nights=3 → [0, 0, 0, 1, 1, 0, 0, 0]
lamps=[1, 1, 0, 0, 1, 0, 1, 1], nights=1000000000 → [0, 1, 1, 1, 0, 1, 0, 0]
Simulating a billion nights one by one is too slow, but after the first night the states start repeating in a cycle.
lamps=[1, 0, 0, 1, 1, 1, 0, 1], nights=1
[0, 0, 0, 0, 1, 0, 1, 0]
Run checks the first 3 tests in your browser. Submit checks all 103 tests on the server, hidden ones included.