You are given an integer array nums. Your goal is to transform this array into a positive array using the minimum number of operations possible.
An array is considered positive if every subarray with more than two elements has a positive sum. In other words, for any subarray nums[i...j] where j - i + 1 > 2, the sum of all elements in that subarray must be greater than 0.
Operation: You can replace any element in the array with any integer between -1018 and 1018.
Your task: Find the minimum number of operations needed to make the array positive.
Example: For array [1, -5, 2, -3], the subarray [1, -5, 2] has sum -2 (negative), and [-5, 2, -3] has sum -6 (negative). We need to fix these violations with minimum operations.
Input & Output
Constraints
- 1 โค nums.length โค 1000
- -1018 โค nums[i] โค 1018
- At least 60% of subarrays must have length > 2
- Replacement values must be between -1018 and 1018