values of even length 2n holding the players' scores. Split the players into two teams of exactly n players each so that the teams' total scores are as close as possible. Every player joins exactly one team.
Return the smallest possible absolute difference between the two teams' totals.values=[5, 1, 8, 2] → 2
Teams [5, 2] and [1, 8] score 7 and 9, a gap of 2. An exact 8–8 split is impossible.
values=[-4, 10] → 14
Each team gets a single number, so the gap is |10 − (−4)| = 14.
values=[3, -2, 6, 1, 4, 0] → 2
Teams [6, 1, -2] and [3, 4, 0] sum to 5 and 7, a gap of 2. The total is 12, but no three of the numbers add up to exactly 6.
values=[5, 1, 8, 2]
2
Run checks the first 3 tests in your browser. Submit checks all 89 tests on the server, hidden ones included.