Linear pass using 2 pointers in C++.
We need to maintain a following invariant: A[i] is an even number at even position and A[j] is an odd number at odd position. As soon as this invariant is viola
We need to maintain a following invariant: `A[i]` is an even number at even position and `A[j]` is an odd number at odd position. As soon as this invariant is violated, it\'s possible to swap numbers to restore it.\n\n```\nclass Solution {\npublic:\n    vector<int> sortArrayByParityII(vector<int>& A) {\n        for (int i = 0, j = 1; j < A.size() && i < A.size();) {\n            if (A[i] % 2 == 0) {\n                i += 2;\n            } else if (A[j] % 2 == 1) {\n                j += 2;\n            } else {\n                swap(A[i], A[j]);\n            }\n        }\n        return A;\n    }\n};\n```
[]