Two Solutions ✅|| Equal Complexity || Varied Runtimes ⏱️🚀 || JAVA ☕
Intuition\nThe goal is to ensure each element in the array is strictly greater than the previous element. If an element is not greater than the previous one, we
# Intuition\nThe goal is to ensure each element in the array is strictly greater than the previous element. If an element is not greater than the previous one, we need to increase it to be at least one more than the previous element.\n\n# Approach\n1. Initialize a counter count to keep track of the total number of operations needed.\n1. Iterate through the array starting from the second element.\n1. For each element, check if it is less than or equal to the previous element.\n1. If it is, calculate the difference needed to make it one more than the previous element.\n1. Add this difference to count and update the current element to the new value.\n1. Return count as the result.\n\n# Complexity\n**- Time complexity:** **O(n)**, where n is the length of the array. This is because we only iterate through the array once.\n\n**- Space complexity:** ****O(1)****, as we are using a constant amount of extra space.\n\n# RUNTIME : \nHere we are UPDATING an ARRAY. **Updating** **nums[i] costs more time**.\n\n \n![Screenshot 2024-06-14 100110.png](https://assets.leetcode.com/users/images/2c1749e1-e426-431e-bda5-0ee625b6e7ba_1718340000.5766306.png)\n\n\n\n\n# Code-1 : Updating nums[] -\n```\n class Solution {\n     public int minOperations(int[] nums) {\n\n         // UPDATING ARRAY -> cost more time\n         if(nums.length <= 1) {\n             return 0;\n         }\n\n         int count = 0;\n         for(int i=1 ; i<nums.length ; i++) {\n             if(nums[i] <= nums[i-1]) {\n                 count += nums[i-1] + 1 - (nums[i]);\n                 nums[i] = nums[i-1] + 1;\n             }\n         }\n\n         return count;\n    }\n }\n\n```\n\n# Code-2 : Updating variable - \n**Updating** the **value of variable** prev **cost less time** than updating the nums[i].\n\n![Screenshot 2024-06-14 100557.png](https://assets.leetcode.com/users/images/bc6f0b60-2379-4c71-8181-b93bc38429ef_1718340876.778456.png)\n\n\n```\n\nclass Solution {\n    public int minOperations(int[] nums) {\n// UPDATING VARIABLE -> cost less time\n\n        if(nums.length == 1) {\n            return 0;\n        }\n\n        int count =  0;\n        int prev = nums[0];\n        for(int i=1 ; i<nums.length ; i++) {\n            if(prev == nums[i]) {\n                prev++;\n                count++;\n            }\n            else if(prev > nums[i]) {\n                prev++;\n                count += prev - (nums[i]);\n            }\n            else {\n                prev = nums[i];\n            }\n        }\n\n        return count;\n    }\n}\n```\n\n
['Java']