Minimum Operations to Make the Array K-Increasing
You are given a 0-indexed array arr consisting of n positive integers, and a positive integer k.
The array arr is called K-increasing if arr[i-k] <= arr[i] holds for every index i, where k <= i <= n - 1.
In one operation, you can choose an index i and change arr[i] into any positive integer.
Return the minimum number of operations required to make the array K-increasing for the given k.
Example 1
Input
arr = [5,4,3,2,1], k = 1Output
4For k = 1, the resultant array has to be non-decreasing, and it can be shown that at least 4 changes are required.
Example 2
Input
arr = [4,1,5,2,6,2], k = 2Output
0The array is already K-increasing for k = 2, so no operations are needed.
Constraints
- 1 <= arr.length <= 10^5
- 1 <= arr[i], k <= arr.length