values of 3n integers. Remove exactly n elements of your choice (they need not be adjacent); the remaining 2n keep their original order.
The remaining array is cut in half: the first n elements form the left half and the next n the right half. The difference is the sum of the left half minus the sum of the right half, and it may be negative.
Return the smallest possible difference.values=[4, 2, 6] → -4
Here n = 1. Removing 6 leaves [4, 2] with 4 - 2 = 2; removing 4 leaves [2, 6] with 2 - 6 = -4; removing 2 leaves [4, 6] with -2. The minimum is -4.
values=[5, 1, 8, 2, 7, 3] → -9
n = 2. Removing 2 and 3 leaves [5, 1, 8, 7], so the difference is (5 + 1) - (8 + 7) = -9. Nothing smaller is possible.
values=[9, 9, 9, 9, 9, 9, 9, 9, 9] → 0
values=[4, 2, 6]
-4
Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.