Skip to content

Commit e150333

Browse files
solves minimum operations to make the array increasing
1 parent b40f3ba commit e150333

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@
444444
| 1816 | [Truncate Sentence](https://leetcode.com/problems/truncate-sentence) | [![Java](assets/java.png)](src/TruncateSentences.java) | |
445445
| 1822 | [Sign of the Product of an Array](https://leetcode.com/problems/sign-of-the-product-of-an-array) | [![Java](assets/java.png)](src/SignOfTheProductOfAnArray.java) | |
446446
| 1826 | 🔒 [Faulty Sensor](https://leetcode.com/problems/faulty-sensor) | | |
447-
| 1827 | [Minimum Operations to Make the Array Increasing](https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing) | | |
447+
| 1827 | [Minimum Operations to Make the Array Increasing](https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing) | [![Java](assets/java.png)](src/MinimumOperationsToMakeTheArrayIncreasing.java) | |
448448
| 1832 | [Check if the Sentence Is Pangram](https://leetcode.com/problems/check-if-the-sentence-is-pangram) | | |
449449
| 1837 | [Sum of Digits in Base K](https://leetcode.com/problems/sum-of-digits-in-base-k) | | |
450450
| 1844 | [Replace All Digits with Characters](https://leetcode.com/problems/replace-all-digits-with-characters) | | |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing
2+
// T: O(N)
3+
// S: O(1)
4+
5+
public class MinimumOperationsToMakeTheArrayIncreasing {
6+
public int minOperations(int[] nums) {
7+
int operations = 0;
8+
for (int index = 1, current = nums[0] ; index < nums.length ; index++) {
9+
operations += Math.max(0, current - nums[index] + 1);
10+
current = Math.max(current + 1, nums[index]);
11+
}
12+
return operations;
13+
}
14+
}

0 commit comments

Comments
 (0)