Skip to main content
Back to problems
#1827
Easy Algorithms

Minimum operations to make the array increasing

Array Greedy
81.9% acceptance
Feb 25, 2026
1317
68
You are given an integer array nums (0-indexed). In one operation, you can choose an element of the array and increment it by 1. Return the minimum number of operations needed to make nums strictly increasing. An array nums is strictly increasing if nums[i] < nums[i+1] for all 0 <= i < nums.length - 1.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn min_operations(nums: Vec<i32>) -> i32 {
    let mut ops = 0i32;
    let mut prev = nums[0];
    for i in 1..nums.len() {
      let needed = prev + 1;
      if nums[i] < needed {
        ops += needed - nums[i];
        prev = needed;
      } else {
        prev = nums[i];
      }
    }
    ops
  }
}