SIMPLE TWO-POINTER C++ COMMENTED  SOLUTION
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:o(n)\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```\n\nclass Solution {\npublic:\n/*\n      // Example dry run with nums = [5, 2, 4, 7]:\n        // Initial state: nums = [5, 2, 4, 7], i = 0, j = 1\n        // First iteration: i = 0 (5 is odd), j = 1 (2 is even), swap -> nums = [2, 5, 4, 7]\n        // i moves to 2, j moves to 3\n        // Second iteration: i = 2 (4 is even), j = 3 (7 is odd), no swap needed\n        // i moves out of bounds, loop exits\n        // Final state: nums = [2, 5, 4, 7]\n*/\n    std::vector<int> sortArrayByParityII(std::vector<int>& nums) {\n        int n = nums.size();\n        int i = 0; // even indices\n        int j = 1; // odd indices\n        while (i < n && j < n) {\n            if (nums[i] % 2 == 0){\n                i += 2;// Move to the next even index\n            }else if (nums[j] % 2 == 1){\n                j+=2; // Move to the next odd index\n            }else{\n                swap(nums[i], nums[j]); \n                i+=2;\n                j+=2;\n            }\n        }\n  \n\n        return nums;\n    }\n};\n```
['C++']