[C++] Every element is n | Time : O(n) | Space : O(1)
\n\nA simple O(n) solution is to set every element to n.\nNow since we can get two elements close to n at the same time ({a[0], a[n-1]}, {a[1], a[n-2]} .. {a[n/
\n\nA simple O(n) solution is to set every element to n.\nNow since we can get two elements close to n at the same time ({a[0], a[n-1]}, {a[1], a[n-2]} .. {a[n/2], a[n/2]})\n\nWe just need to iterate i from 0 to n/2 and find the distance between n and 2*i + 1\n\nTime Complexity : `O(n)`\nSpace Complexity : `O(1)`\n\n```\nclass Solution {\npublic:\n    int minOperations(int n) {\n        int ops = 0;\n        for(int i=0; i<n/2; i++) {\n            int curr = (2*i) + 1;\n            ops += abs(n-curr);\n        }\n        return ops;\n    }\n};\n```
[]