items.
You may take any items off the shelf (or none), and the rest keep their order. The display is finished if at least two items remain and the leftmost and rightmost ones have the same value.
Return the largest total value of a finished display.items=[4, -2, 7, 4, 3, 7] → 21
Keep 7, 4, 3, 7: the ends match and the sum is 21. Using the 4s as ends gives only 4 + 7 + 4 = 15.
items=[-5, 6, -1, -3, -1] → -2
The only equal pair is the two -1s. The -3 between them is dropped: -1 + -1 = -2.
items=[2, 2] → 4
len(items) ≤ 10⁵items[i] ≤ 10⁴items twiceitems=[4, -2, 7, 4, 3, 7]
21
Run checks the first 3 tests in your browser. Submit checks all 129 tests on the server, hidden ones included.