Minimum Operations to Make the Array Increasing - Problem

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.

For example, if nums = [1,2,3], you can choose to increment nums[1] to make nums = [1,3,3].

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. An array of length 1 is trivially strictly increasing.

Input & Output

Example 1 — Basic Case
$ Input: nums = [1,1,1]
Output: 3
💡 Note: After 3 operations: [1,2,3]. Operations: increment nums[1] to 2 (1 op), increment nums[2] to 3 (2 ops).
Example 2 — Partially Sorted
$ Input: nums = [1,5,2,4,1]
Output: 14
💡 Note: Transform to [1,5,6,7,8]. Operations: nums[2]: 2→6 (4 ops), nums[3]: 4→7 (3 ops), nums[4]: 1→8 (7 ops). Total: 14.
Example 3 — Already Sorted
$ Input: nums = [8]
Output: 0
💡 Note: Single element array is already strictly increasing, no operations needed.

Constraints

  • 1 ≤ nums.length ≤ 1000
  • 1 ≤ nums[i] ≤ 1000

Visualization

Tap to expand
Problem Overview: Make Array Strictly Increasing111Input: Not Strictly IncreasingApply Increment Operations123Result: Strictly IncreasingAnswer: 3
Understanding the Visualization
1
Input
Array [1,1,1] where elements are not strictly increasing
2
Process
Increment elements to make each one greater than the previous
3
Output
Return total number of increment operations needed
Key Takeaway
🎯 Key Insight: Only increment elements to be exactly one more than the previous element
Asked in
Google 15 Amazon 12 Facebook 8
23.4K Views
Medium Frequency
~15 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen