Beats 100% | Constant time | C++
Intuition\n Describe your first thoughts on how to solve this problem. \nIt is given that the $i^{th}$ element is the $i+1^{th}$ odd number, now after taking a 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIt is given that the $i^{th}$ element is the $i+1^{th}$ odd number, now after taking a closer look you can see in every case all the elements finally become n, i.e. the size of the array\n\n[1, 3, 5, 7] gets turned into [4, 4, 4, 4] after 4 operations\n[1, 3, 5, 7, 9] gets turned into [5, 5, 5, 5, 5] after 6 operations\n# Approach\n<!-- Describe your approach to solving the problem. -->\nNow we can simply calculate the number of operations required to turn the whole array to n, after carefull examining we can conclude that\n#### For odd number of elements :\n [1, 3, 5, 7, 9]\nThe pair (1,9) requires 4 operations to turn into 5,5\nThe pair (3,7) requires 2 operations to turn into 5,5\n\nThis can be generalized to form an ap of first n/2 odd numbers, which in this case are the first 2 odd numbers\n\n##### For even number of elements :\n [1, 3, 5, 7]\nThe pair (1,7) requires 3 operations to turn into 4,4\nThe pair (3,5) requires 1 operations to turn into 4,4\n\nThis can be generalized to form an ap of first n/2 even numbers, which in this case are the first 2 even numbers\n\n# Complexity\n- Time complexity: O(1)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int minOperations(int n) {\n        if(n%2)     // condition odd\n        {\n            return n/2*(2+(n/2)-1);\n        }\n        return n/2*(1+(n/2)-1); \n    }\n};\n```
['Math', 'C++']