Problem statement

https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/

Solution

Start from the left element and increase element until it is bigger than previous.

Complexity

It is O(n) for time and space.

Code

class Solution:
    def minOperations(self, nums):
        n, ans = len(nums), 0
        for i in range(1, n):
            if nums[i] <= nums[i-1]:
                ans += nums[i-1] + 1 - nums[i]
                nums[i] = nums[i-1] + 1
        return ans