Python O(1)
\nIt a simple math problem.\n\nConsider an example and understand the hidden logic.\n\nlet n is odd and n = 5\nArray -      [1,3,5,7,9]\nAddOns - [4,2,0,-2,-4]\
\nIt a simple math problem.\n\nConsider an example and understand the hidden logic.\n\nlet n is odd and n = 5\nArray -      [1,3,5,7,9]\nAddOns - [4,2,0,-2,-4]\nSo we require 2+4 operations.\nAs n is 5 we require 2(Arithemtic progression sum of 5//2 numbers) = 2(1+2)\nif n is 10 we require 2(Arithemtic progression sum of 10//2 numbers) = 2(1+2+3+4+5)\n\nLet\'s assume mid = n//2\nReduce above into a formula:\n2((mid*(mid+1))//2) = mid*(mid+1)\n\nIf n is even:\nFor example n is 6.\n\tArray = [1,3,5,7,9,11]\nAddons = [5,3,1,-1,-3,-5]\nNumber of operations = (1+3+5)\nIt is equal to AP sum of n//2 (Assume it as mid) odd numbers.\nApply summation for 2*mid + 1, it will result as mid**2\n\n```\nclass Solution:\n    def minOperations(self, n: int) -> int:\n        mid = n//2\n        return mid * (mid + n%2)\n```\n\nTime ans space complexity - O(1)\n\nIf it is helpful, please upvote.
['Math']