Loading...
Loading...
Loading...
You must flip the sign of exactly one number in a list, k times in a row. The same number may be flipped again. Print the largest sum you can reach.
Example 1
Input
4 2 3 1
Output
5
Example 2
Input
3 -1 0 2 3
Output
6
Try the problem first. Open one hint at a time.
Flipping the smallest number each time is the best move.
Use a min-heap: pop the smallest, flip it, push it back, k times.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor