2234. Minimum Operations to Make the Array K-Increasing
My accepted Python solution to LeetCode problem 2234, Minimum Operations to Make the Array K-Increasing, running in 174ms.
- Difficulty: Hard
- Python
- Runtime 174ms
- Memory 30.1MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 174ms, memory 30.1MB, accepted 2025-12-29.
class Solution:
def kIncreasing(self, arr: List[int], k: int) -> int:
import bisect
def longestNonDecreasing(nums):
# LIS with non-decreasing (allow equal)
tails = []
for num in nums:
pos = bisect.bisect_right(tails, num)
if pos == len(tails):
tails.append(num)
else:
tails[pos] = num
return len(tails)
total = 0
for i in range(k):
# Extract every k-th element starting from i
subarray = [arr[j] for j in range(i, len(arr), k)]
# Operations needed = length - longest non-decreasing subsequence
total += len(subarray) - longestNonDecreasing(subarray)
return total