values. Choose a non-empty subsequence: some of the elements in their original order, not necessarily adjacent. Then give them alternating signs: the first one plus, the second minus, the third plus, and so on.
Return the largest sum you can get this way.values=[7, 3, 8, 1, 4] → 15
Taking every number is best: 7 - 3 + 8 - 1 + 4 = 15.
values=[2, 9, 5] → 9
Taking just 9 is enough. For example, [9, 5] would give only 4.
values=[5, 1, 5, 1, 5] → 13
values=[7, 3, 8, 1, 4]
15
Run checks the first 3 tests in your browser. Submit checks all 95 tests on the server, hidden ones included.