values are arranged in a circle: after the last element comes the first one again. Choose a non-empty run of consecutive elements on this ring (it may wrap past the end of the array to the start) and return the largest possible sum.
Each element can appear in the run at most once, so the run is no longer than len(values).values=[6, -10, 2, 3] → 11
A segment may wrap past the end back to the start: 2 + 3 + 6 = 11.
values=[-1, 4, -2, 5, -9] → 7
The best segment here does not wrap: 4 - 2 + 5 = 7.
values=[-8, -3, -5] → -3
All numbers are negative and the segment cannot be empty, so take -3.
values=[6, -10, 2, 3]
11
Run checks the first 3 tests in your browser. Submit checks all 120 tests on the server, hidden ones included.