n lamps, numbered 1 to n, starts with every lamp off. The array order is a permutation of 1 to n: on step i (1-based) lamp order[i - 1] is switched on and stays on.
A run is a maximal stretch of consecutive lit lamps, meaning the lamps immediately to its left and right (if any) are off.
Return the last step after which the row contains at least one run of length exactly size. If there is no such step, return -1.order=[2, 4, 1, 3], size=2 → 3
States: 0100, 0101, 1101, 1111. After step 3 there is a run 11 of length 2; after step 4 everything merges into one run of length 4. The answer is 3.
order=[1, 3, 2], size=2 → -1
States: 100, 101, 111. A run of length exactly 2 never appears, so the answer is -1.
order=[3, 1, 2], size=3 → 3
order is a permutation of 1, 2, …, norder=[2, 4, 1, 3], size=2
3
Run checks the first 3 tests in your browser. Submit checks all 109 tests on the server, hidden ones included.