pieces.
You share the cake with two friends: you pick any remaining piece, then one friend takes the nearest remaining piece counterclockwise from it and the other takes the nearest one clockwise. This repeats until the cake is gone.
Return the largest total size you can collect for yourself.pieces=[2, 5, 3, 6, 1, 4] → 11
Take the 6; its neighbors 3 and 1 go to the friends. The circle [2, 5, 4] remains; take the 5 and the friends get 2 and 4. Total 6 + 5 = 11.
pieces=[7, 9, 7, 3, 2, 2] → 14
Taking the 9 hands both 7s to the friends. It is better to take the two 7s one after another: 7 + 7 = 14.
pieces=[4, 1, 8] → 8
pieces=[2, 5, 3, 6, 1, 4]
11
Run checks the first 3 tests in your browser. Submit checks all 86 tests on the server, hidden ones included.