lights[i]. A keeper puts them out one at a time, in any order he likes, until all are dark.
Putting out a lantern earns points: its brightness times the brightness of the nearest still-lit lantern on its left and the nearest still-lit lantern on its right. If no lit lantern remains on one side, that side counts as 1. A lantern that has been put out drops out of the row, so its former neighbours become adjacent.
Return the largest total score the keeper can collect.lights=[2, 4, 3] → 33
The best order is 4 first (2·4·3 = 24), then 2 (1·2·3 = 6), then 3 (1·3·1 = 3): 33 in total.
lights=[6] → 6
A single lantern has no neighbours, so both sides count as 1: 1·6·1 = 6.
lights=[3, 0, 5] → 20
lights=[2, 4, 3]
33
Run checks the first 3 tests in your browser. Submit checks all 93 tests on the server, hidden ones included.