Tap here to switch tabs
Problem
Submissions

Problem: Maximize Sum Of Array After K Negations

med
30 min
Try to solve the Maximize Sum Of Array After K Negations problem.

Statement

Given an integer array nums and an integer k, modify the array by selecting an index i and replacing nums[i] with -nums[i] exactly k times. You may select the same index i multiple times.

Return the maximum possible sum of the array after applying k modifications.

Constraints:

  • 1≤1 \leq nums.length ≤104\leq 10^4

  • −100≤-100 \leq nums[i] ≤100\leq 100

  • 1≤1 \leq k ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximize Sum Of Array After K Negations

med
30 min
Try to solve the Maximize Sum Of Array After K Negations problem.

Statement

Given an integer array nums and an integer k, modify the array by selecting an index i and replacing nums[i] with -nums[i] exactly k times. You may select the same index i multiple times.

Return the maximum possible sum of the array after applying k modifications.

Constraints:

  • 1≤1 \leq nums.length ≤104\leq 10^4

  • −100≤-100 \leq nums[i] ≤100\leq 100

  • 1≤1 \leq k ≤104\leq 10^4