Minimum Increase to Maximize Special Indices
You are given an integer array nums of length n.
An index i where 0 < i < n - 1 is special if nums[i] > nums[i - 1] and nums[i] > nums[i + 1].
You may perform operations where you choose any index i and increase nums[i] by 1.
Your goal is to:
- Maximize the number of special indices.
- Minimize the total number of operations required to achieve that maximum.
Return an integer denoting the minimum total number of operations required.
Example 1
Input
nums = [1,2,2]Output
1Increasing
nums[1] once gives [1, 3, 2], which has 1 special index, the maximum achievable, with the fewest operations.Example 2
Input
nums = [2,1,1,3]Output
2Performing 2 operations at index
1 gives [2, 3, 1, 3], which has 1 special index, the maximum achievable.Constraints
- 3 <= n <= 10^5
- 1 <= nums[i] <= 10^9