Problem · Array
Maximize the Array Sum After Negating at Most K Elements 🥝
Learn this problemProblem statement
Given an array A with only positive numbers. We are allowed to negate any entries in the array,
(i.e set A[i] = -A[i]). What is the maximum number of entries you can negate in the array such
that every prefix sum after the negate operations is positive.
Function
maxNegations(A: int[]) → intExamples
Example 1
A = [4, 1, 1, 1]return = 3We can apply only at-most 3 negate operations, to make A = [4, -1, -1, -1], after the negate operation,
The prefix sums of A, p(A) = [4, 3, 2, 1] which are all positive. So that the answer for A is 3.
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026