Problem · Array

Make the Array Positive

Learn this problem
HardAtlassian logoAtlassianFULLTIMEOA

Problem statement

An operation replaces any one array value with any signed 64-bit integer. An array is positive when every contiguous subarray of length greater than one has non-negative sum. Return the minimum operations required.

Function

getMinOperations(arr: int[]) → int

Examples

Example 1

arr = [2,5,-8,-1,2]return = 1

Replacing -8 with a sufficiently large positive value makes every length-at-least-two subarray non-negative.

Constraints

  • 1 <= arr.length <= 100000
  • -10^9 <= arr[i] <= 10^9

More Atlassian problems

drafts saved locally
public int getMinOperations(int[] arr) {
  // Write your code here.
}
arr[2,5,-8,-1,2]
expected1
checking account