brightness[i] is the brightness of bulb i, and all values are distinct. The designer dislikes "smooth steps": spots where a bulb's brightness is exactly the average of its two neighbours. The bulbs at either end have only one neighbour, so the rule does not apply to them.
There is a simple way to hang the bulbs with no smooth steps. Sort the brightness values in ascending order. The first ⌈n/2⌉ values form the dim half and the rest form the bright half. Hang the bulbs alternating between the halves: the dimmest of the dim half, the dimmest of the bright half, the second of the dim half, the second of the bright half, and so on.
Return the garland built exactly this way. Think about why it never contains a smooth step.brightness=[7, 1, 4, 9, 3] → [1, 7, 3, 9, 4]
Sorted: 1, 3, 4, 7, 9. The dim half is 1, 3, 4 and the bright half is 7, 9. Alternating them gives [1, 7, 3, 9, 4]. No bulb equals the average of its neighbours: for instance, (1 + 3) / 2 = 2 ≠ 7.
brightness=[20, 50, 10, 40] → [10, 40, 20, 50]
Sorted: 10, 20, 40, 50. The halves are 10, 20 and 40, 50, so the result is [10, 40, 20, 50].
brightness=[2, 0, 1] → [0, 2, 1]
brightness are distinctbrightness=[7, 1, 4, 9, 3]
[1, 7, 3, 9, 4]
Run checks the first 3 tests in your browser. Submit checks all 105 tests on the server, hidden ones included.