Skip to content

Practice Minimum Operations to Make the Array K-Increasing

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2111
LeetCode Problem

Minimum Operations to Make the Array K-Increasing

Problem Statement

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.

Source: Minimum Operations to Make the Array K-Increasing on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
arr = [5,4,3,2,1], k = 1
Output
4

# Example 2

Input
arr = [4,1,5,2,6,2], k = 2
Output
0

# Example 3

Input
arr = [4,1,5,2,6,2], k = 3
Output
2

Constraints

1 <= arr.length <= 10^5
1 <= arr[i], k <= arr.length

Related LeetCode Problems

Practice more problems similar to Minimum Operations to Make the Array K-Increasing.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.