values and an integer flips. One operation picks any index i and replaces values[i] with -values[i].
You must perform exactly flips operations; the same index may be picked any number of times.
Return the largest possible sum of the array after all the operations.values=[-6, 2, -1, 4], flips=2 → 13
Flip -6 and -1 to get [6, 2, 1, 4], which sums to 13.
values=[3, 5, 1], flips=3 → 7
There are no negatives, and an odd number of flips must leave one number negative. The cheapest is 1: [3, 5, -1], sum 7.
values=[-2, 0, 7], flips=4 → 9
len(values) ≤ 10⁴values[i] ≤ 100flips ≤ 10⁴values=[-6, 2, -1, 4], flips=2
13
Run checks the first 3 tests in your browser. Submit checks all 121 tests on the server, hidden ones included.