values. Choose a contiguous segment of it and, if you like, throw out one of its elements. At least one element must remain afterwards.
Return the largest sum you can get this way.values=[4, -5, 2, 6] → 12
Take the whole array and drop -5: 4 + 2 + 6 = 12.
values=[-3, 7, -8, -8, 1] → 7
One skip cannot remove both -8s, so the best is just 7 on its own.
values=[-4, -2, -6] → -2
The segment must not end up empty, so the answer is the single value -2.
values=[4, -5, 2, 6]
12
Run checks the first 3 tests in your browser. Submit checks all 142 tests on the server, hidden ones included.