3 Approaches || one Line Solution || 100%fast || O(1)
\n\nclass Solution {\npublic:\n    int minOperations(int n) {\n    vector<int>nums(n);\n        for(int i=0;i<n;i++){\n            nums[i] = (2 * i) + 1;\n     
\n```\nclass Solution {\npublic:\n    int minOperations(int n) {\n    vector<int>nums(n);\n        for(int i=0;i<n;i++){\n            nums[i] = (2 * i) + 1;\n        }\n        int ans=0;\n        for(int i=0;i<n/2;i++){\n            int diff=nums[n-i-1]-nums[i];\n            ans+=diff/2;\n        }\n        return ans;\n    }\n};\n```\n\n```\nclass Solution {\npublic:\n    int minOperations(int n) {\n    return(n*n)/4 ;\n    }\n};\n```\n\n\n```\n\n\nHere is my cpp one liner with explanation\n\nThere are two possible cases\nn is odd\nlet\'s consider n=5.\narray contains\n1 3 5 7 9\nHere, middle element of array is -> 5.\nNow, we need to choose elements in a pair (which are not equal to the mid element), perform some operation on a pair to make them equal to middle element.\nLet\'s take pair (3,7) ,We will decrement 7 and incement 3, two times to make them equal to 5(middle element).\nSo it takes 2 steps.\nLet\'s take another pair (1,9) We will decrement 9 and incement 1, four times to make them equal to 5.\nSo it takes 4 steps.\nAfter performing these steps, all elements will become 5.\nSo, Total steps: 2+4=6. (sum of first n/2 even numbers)\nSum of first k EVEN numbers = k(k+1)\nans would be n/2(n/2+1)\nn is even\nlet\'s consider n=6.\narray contains\n1 3 5 7 9 11\nHere, middle element of array is -> (5+7)/2=6.\nLet\'s take pair (5,7), We will decrement 7 and incement 5, one time to make them equal to 6.\nSo it takes 1 step.\nLet\'s take 2nd pair (3,9), We will decrement 9 and incement 3, three times to make them equal to 6.\nSo it takes 3 steps.\nLet\'s take last pair (1,11), We will decrement 11 and incement 1, five times to them equal to 6.\nSo it takes 5 steps.\nAfter performing these steps, all elements will become 6.\nTotal steps: 1+3+5=9. (sum of first n/2 odd numbers)\nSum of first k ODD numbers = k*k.\nans would be n/2*n/2\n\n\n```\n```\nclass Solution {\npublic:\n    int minOperations(int n) {\n       return n&1 ? n/2*(n/2+1) : n/2*n/2 ;\n    }\n};\n```\n
['Math', 'C', 'C++']