[Python3] Easy Solution without Modifying Array
Modifying mutable input data is bad practice in Python for functions like this, because when using it, the user may not be aware of the changes, and this will l
Modifying mutable input data is bad practice in Python for functions like this, because when using it, the user may not be aware of the changes, and this will lead to subsequent errors.\nWe can solve this problem without modifying a list by using an additional variable (`max_elem`).\n\nAlgo:\n*   Initialize variables: `n_operations` with `0` and `max_elem` with `0`.\n* \tIterate over the input array\n\t* \tCompare `cur_elem` with `max_elem`\n\t* \tIf `cur_elem` > `max_elem`:\n\t\t* \tThen we update `max_elem`  to the value of `cur_elem`\n\t*   If `cur_elem` <= `max_elem`:\n\t\t*   Then we **calculate current minimum number of operations** needed for cur_elem to be the maximum of all previous elements (`max_elem - cur_num + 1`)\n\t\t*   Add the **current minimum number of operations** to the total (`n_operations`)\n\t\t*   And update our current `max_elem` with `max_elem += 1`, because our new maximum is 1 more than the previous one.\n*  Return result (`n_operations`) \n\n```Python\ndef minOperations(self, nums: List[int]) -> int:\n        n_operations = 0\n        max_elem = 0\n        \n        for cur_num in nums:\n            if cur_num <= max_elem:\n                n_operations += max_elem - cur_num + 1\n                max_elem += 1\n            else:\n                max_elem = cur_num\n        return n_operations\n```\n\n**Complexity:**\n**Time:** Linear `O(n)`\n**Memory:** `O(1)`, we use only constant memory
['Python']