n lamps numbered 1 to n, all off at first. Exactly one lamp is switched on each day: on day i + 1 it is lamp number order[i]. After n days every lamp is on.
Find the earliest day after which there are two lit lamps with exactly gap lamps between them, all of them still off. Return that day (days are numbered from 1), or -1 if no such day exists.order=[2, 5, 4, 1, 3], gap=2 → 2
After day 2 lamps 2 and 5 are on, and lamps 3 and 4 between them are still dark: exactly two. The answer is 2.
order=[3, 1, 2], gap=1 → 2
On day 2 lamps 1 and 3 are on with the single dark lamp 2 between them.
order=[1, 2, 3, 4], gap=1 → -1
Lamps light up one after another, so two lit lamps never have a dark one between them. The answer is -1.
order is a permutation of 1 to norder=[2, 5, 4, 1, 3], gap=2
2
Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.