Array Greedy 1827. Minimum Operations to Make the Array Increasing ¶ Time: O(n)O(n)O(n) Space: O(1)O(1)O(1) C++JavaPython 1 2 3 4 5 6 7 8 9 10 11 12 13 14class Solution { public: int minOperations(vector<int>& nums) { int ans = 0; int last = 0; for (const int num : nums) { ans += max(0, last - num + 1); last = max(num, last + 1); } return ans; } }; 1 2 3 4 5 6 7 8 9 10 11 12 13class Solution { public int minOperations(int[] nums) { int ans = 0; int last = 0; for (final int num : nums) { ans += Math.max(0, last - num + 1); last = Math.max(num, last + 1); } return ans; } } 1 2 3 4 5 6 7 8 9 10class Solution: def minOperations(self, nums: list[int]) -> int: ans = 0 last = 0 for num in nums: ans += max(0, last - num + 1) last = max(num, last + 1) return ans Was this page helpful? Thanks for your feedback! Thanks for your feedback! Help us improve this page by using our feedback form.