values of length n. Its elements play three roles:
- n − 2 elements are **addends**;
- one element is the **total**, equal to the sum of all addends;
- one more element is the **stray**, unrelated to the rest.
You don't know in advance which element plays which role, and there may be several valid assignments. Every element plays exactly one role, but elements in different roles may share a value.
Return the largest value the stray element can have.values=[4, 1, 3, 9, 8] → 9
If 9 is the stray, the remaining 4, 1 and 3 sum to 8, which is in the array. Every other split gives a smaller stray.
values=[-5, 2, -3, 7] → 7
-5 and 2 sum to -3, so the stray is 7.
values=[6, 2, 2, 2, 6] → 6
Three 2s add up to 6 and the other 6 is the stray: equal values are fine as long as they are different elements.
values=[4, 1, 3, 9, 8]
9
Run checks the first 3 tests in your browser. Submit checks all 41 tests on the server, hidden ones included.