C++ Simple Math Solution || O(1)
There are two cases that can arise:\n1. If n is odd\n2. If n is even\n\nNow lets see what happens when n is odd, say 5. \nWe have array as [1,3,5,7,9]\nNow we c
There are two cases that can arise:\n1. If n is odd\n2. If n is even\n\nNow lets see what happens when n is odd, say 5. \nWe have array as [1,3,5,7,9]\nNow we can make all the elements equal to the mid element. So the total operation would be [4,2,0,2,4]. As we can clearly see that we will not add the right side of zero as we can two element at a time so we will add 4 + 2 + 0 = 6. In this way we can derive a formula that is (n/2) * (n/2 + 1) {Sum of n/2 even number}.\n\nNow if n is even, say 6.\nWe have array as [1,3,5,7,9,11]\nHere we can make all the elements equal to the average of (n-1)/2 and n/2. The average comes out to be (5+7)/2 = 6. So the total operations would be [5,3,1,1,3,5]. Now, we will sum the operations and divide it by 2 because we can take 2 elements at a time. The sum of n/2 odd numbers is n * n. So, 3 * 3 = 9.\n\n```\nclass Solution {\npublic:\n    int minOperations(int n) {\n        if(n%2 == 0) {\n            return (n/2) * (n/2);\n        }\n        else {\n            n = n-1;\n            return ((n/2) * ((n/2) + 1));\n        }\n    }\n};\n```
['Math', 'C', 'C++']