LeetCode solutions

1938. Minimum Operations to Make the Array Increasing

My accepted Python solution to LeetCode problem 1938, Minimum Operations to Make the Array Increasing, running in 99ms.

  • Difficulty: Easy
  • Python
  • Runtime 99ms
  • Memory 18MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 99ms, memory 18MB, accepted 2025-12-29.

python
class Solution:
    def minOperations(self, nums: List[int]) -> int:
        # For each element, it must be > previous
        # Time: O(n), Space: O(1)
        ops = 0
        prev = nums[0]
        for i in range(1, len(nums)):
            if nums[i] <= prev:
                ops += prev + 1 - nums[i]
                prev = prev + 1
            else:
                prev = nums[i]
        return ops

Source