Sort Array By Parity II | Inplace | O(n) time | C++
explanation:\nfor every no. there are two possibilities: either its correct on its position or not correct.\nalso as there are equal no. of odd and even nos, so
explanation:\nfor every no. there are two possibilities: either its correct on its position or not correct.\nalso as there are equal no. of odd and even nos, so for every incorrect odd, there will be one incorrect even and vice-versa.\n\nSo we will just keep two pointers : one for odd positions and one for even positions.\nIgnore those which are already at correct position.\nSwap those which are at incorrect.\n\n```\nclass Solution {\npublic:\n    vector<int> sortArrayByParityII(vector<int>& nums) {\n        \n        int i=0;\n        int j=1;\n        \n        while(i<nums.size() && j<nums.size())\n        {\n            while(i<nums.size() && nums[i]%2==0)\n                i+=2;\n            while(j<nums.size() && nums[j]%2==1)\n                j+=2;\n            \n            if(i<nums.size() && j<nums.size())\n            {\n                int temp = nums[i];\n                nums[i] = nums[j];\n                nums[j] = temp;\n            }\n            \n        }\n        return nums;\n    }\n};\n```
['C']