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
- 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 99ms, memory 18MB, accepted 2025-12-29.
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