Skip to content

Latest commit

 

History

History
28 lines (26 loc) · 732 Bytes

2111.md

File metadata and controls

28 lines (26 loc) · 732 Bytes

2111. Minimum Operations to Make the Array K-Increasing

Solution 1 (time O(nlog(n)), space O(n))

class Solution(object):
    def kIncreasing(self, arr, k):
        """
        :type arr: List[int]
        :type k: int
        :rtype: int
        """
        n = len(arr)
        ans = 0
        for i in range(k):
            dp = []
            j, cur_len = i, 0
            while j < n:
                cur_len += 1
                ind = bisect.bisect_right(dp, arr[j])
                if ind == len(dp):
                    dp.append(arr[j])
                else:
                    dp[ind] = arr[j]
                j += k
            ans += cur_len - len(dp)
        return ans