Easy Solution in c++ || Beats 88% of c++ users
Intuition\nGiven an array of integers where half of the integers are even and half are odd, we need to rearrange the array so that every even-indexed position c
# Intuition\nGiven an array of integers where half of the integers are even and half are odd, we need to rearrange the array so that every even-indexed position contains an even number and every odd-indexed position contains an odd number.\n\n# Approach\n1. **Separate Odd and Even Numbers:** Traverse the array and separate the numbers into two different vectors, one for odd numbers and one for even numbers.\n2. **Reconstruct the Array:** Using the two vectors, place the even numbers at the even indices and the odd numbers at the odd indices of the original array.\n\n# Complexity\n- Time complexity:\n**O(N)**\n\n- Space complexity:\n**O(N)**\n![3815c804-b225-4c1f-b62b-c2af5cfc1a0e_1679045089.4677224.jpeg](https://assets.leetcode.com/users/images/f9019711-6399-4c71-8f01-408380dfbb3c_1717748538.8602538.jpeg)\n\n\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> sortArrayByParityII(vector<int>& nums) {\n\n        vector<int> odd, even;\n\n        for(int i = 0; i<nums.size(); i++)\n        {\n            if(nums[i]%2 != 0)\n                odd.push_back(nums[i]);\n            else\n                even.push_back(nums[i]);\n        }\n        for(int i = 0; i<nums.size()/2; i++)\n        {\n            nums[2*i] = even[i];\n            nums[2*i + 1] = odd[i];\n        }\n        return nums;\n        \n    }\n};\n```
['C++']