n lamps numbered 1 to n, all off at first. They are switched on one at a time: at step i (counting from 1) the lamp numbered order[i - 1] goes on. Each lamp is switched on exactly once, so order is a permutation of 1 to n.
After step i the row looks clean if exactly lamps 1, 2, …, i are on and all the others are off.
Return after how many steps the row looked clean.order=[2, 1, 4, 3] → 2
After step 2 lamps 1 and 2 are on, after step 4 all four are. After steps 1 and 3 there is a gap. The answer is 2.
order=[3, 1, 2] → 1
Lamp 3 lights up first, so a clean row appears only at the very end.
order=[1, 2, 3] → 3
The lamps go on in order, so the row is clean after every step: 3.
order is a permutation of 1 to norder=[2, 1, 4, 3]
2
Run checks the first 3 tests in your browser. Submit checks all 94 tests on the server, hidden ones included.