n street lamps lines an alley; lamp i has brightness brightness[i]. At first all of them are on. Then the lamps go out one at a time in the order given by order: at step j, lamp order[j] switches off. Each lamp goes out exactly once.
A **run** is a maximal stretch of adjacent lamps that are still on. The brightness of a run is the sum of its lamps' brightness.
Return an array answer of length n where answer[j] is the largest run brightness right after step j (0 if no lamp is on).brightness=[4, 1, 3, 2, 6], order=[2, 0, 4, 1, 3] → [8, 8, 2, 2, 0]
Lamp 2 goes out: the lit runs are [4, 1] and [2, 6], the best is 8. Lamp 0: [1] and [2, 6], still 8. Lamp 4: [1] and [2], so 2. Lamp 1: only [2] is left, 2. The last lamp goes out: 0.
brightness=[7], order=[0] → [0]
The only lamp goes out and no lit runs remain.
order is a permutation of 0 … n − 1brightness=[4, 1, 3, 2, 6], order=[2, 0, 4, 1, 3]
[8, 8, 2, 2, 0]
Run checks the first 3 tests in your browser. Submit checks all 88 tests on the server, hidden ones included.