Maximum sum after k flips
Your task
You are given a non-empty integer array and a number k >= 1. You must perform exactly k operations; each operation picks one index and flips the sign of that element, and the same index may be picked any number of times. Return the largest possible array sum after the k operations. Example: nums [3, -1, 0, 2] with k = 3 gives 6, flip -1 once, then burn the remaining two flips on the 0.
Examples
max_sum_after_flips(nums: list[int], k: int) -> intExample 1
Input
max_sum_after_flips([3, -1, 0, 2], 3)Output
6