💡 C++ | O(1)  | Simple Logic | With Full Explanation ✏️
Intuition\nThe problem requires finding the minimum number of operations to make all elements of an array equal. The array consists of the first n odd numbers, 
# Intuition\nThe problem requires finding the minimum number of operations to make all elements of an array equal. The array consists of the first `n` odd numbers, i.e., 1, 3, 5, ..., and so on. Since the array is symmetrical, the optimal way to make all numbers equal is to align them with the median value. To do this, we can pair the smallest and largest elements, and make them equal with a minimal number of operations by reducing the difference between them.\n\n\n# Approach\n1. First, generate the array of the first `n` odd numbers, which follow the pattern `(2 * i) + 1`.\n2. The goal is to transform the elements so that all numbers become equal to the median. Since the array is symmetrical, it is enough to consider only the first half of the array. For each element in the first half, compute how much it needs to be incremented to match the corresponding element in the second half.\n3. For each pair of numbers, the difference between them divided by 2 gives the number of operations required to make them equal.\n4. Accumulate the total number of operations and return the result.\n\n# Complexity\n- Time complexity:\n```O(1)```\n\n- Space complexity:\n```O(n)```\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int minOperations(int n) {\n        vector<int> arr;  // Initialize a vector to store the sequence of odd numbers\n        \n        // Fill the vector with the sequence of odd numbers: (2 * i) + 1 for each i from 0 to n-1\n        for (int i = 0; i < n; i++) {\n            arr.push_back((2 * i) + 1);\n        }\n        \n        int ans = 0;  // Initialize the answer to 0 to store the min number of operations\n        \n        // Traverse through the first half of the array and calculate the number of operations needed\n        for (int j = 0; j < (n + 1) / 2; j++) {\n            // Add the difference divided by 2 between the corresponding elements from the start and end\n            ans += ((arr.at(arr.size() - j - 1) - arr.at(j)) / 2);\n        }\n        return ans;\n    }\n};\n\n```\n\n\n![anonupvote.jpeg](https://assets.leetcode.com/users/images/bf7ce48f-1a34-404c-8610-410d43112c2c_1720413559.1746094.jpeg)\n\n# Ask any doubt !!!\nReach out to me \uD83D\uDE0A\uD83D\uDC47\n\uD83D\uDD17 https://tushar-bhardwaj.vercel.app/
['Math', 'C++']