Minimum Increments to Maximize Peak Indices
You are given an integer array nums of length n.
An index i is called a peak index if:
- 0 < i < n - 1
- nums[i] > nums[i - 1]
- nums[i] > nums[i + 1]
In one operation, you may choose any index i and increase nums[i] by 1.
Your task is to make the array contain the maximum possible number of peak indices.
Among all ways to achieve that maximum number of peak indices, return the minimum number of operations required.
Return an integer representing this minimum number of operations.
Example 1:
Input: nums = [1, 1, 1]
Output: 1
Explanation:
- Only index 1 can become a peak.
- Increase nums[1] once to get [1, 2, 1].
- Now index 1 is a peak.
The maximum possible number of peak indices is 1, and it is achieved using 1 operation.
Example 2:
Input: nums = [3, 1, 3, 1, 3]
Output: 6
Now Your Turn!
Pick the correct output for the given inputInput: nums = [4, 1, 2, 1, 4]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 3 <= n <= 105
- 1 <= nums[i] <= 109