Maximize Sum Of Array After K Negations Problem

Maximize Sum Of Array After K Negations Problem — ExecCode Easy DSA Practice

Solve the Maximize Sum Of Array After K Negations problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given an integer array nums and an integer k, modify the array in the following way:. Your task is to compute the required answer and return the largest possible sum of the array after modifying it in this way. choose an index i and replace nums[i] with -nums[i]. You should apply this process exactly k times. You may choose the same index i multiple times.

Examples

Input {"nums": [4, 2, 3], "k": 1}; Output 5. Input {"nums": [3, -1, 0, 2], "k": 3}; Output 6

Constraints

1 <= nums.length <= 10^4 -100 <= nums[i] <= 100 1 <= k <= 10^4

Practice Maximize Sum Of Array After K Negations free on ExecCode. Browse DSA problems, topic map, and placement guides.