C++ 5 lines, two pointers + 2-liner bonus
Use two pointers to search for missplaced odd and even elements, and swap them.\n\nvector<int> sortArrayByParityII(vector<int>& A) {\n    for (int i = 0, j = 1;
Use two pointers to search for missplaced odd and even elements, and swap them.\n```\nvector<int> sortArrayByParityII(vector<int>& A) {\n    for (int i = 0, j = 1; i < A.size(); i += 2, j += 2) {\n        while (i < A.size() && A[i] % 2 == 0) i += 2;\n        while (j < A.size() && A[j] % 2 == 1) j += 2;\n        if (i < A.size()) swap(A[i], A[j]);\n    }\n    return A;\n}\n```\nNow, some fun for for my minimalistic functional friends. It\'s techically a two-liner, though I split ```swap``` into 3 lines for readability :) It actually may even look a bit cleaner, as you do not have to do "plus 2".\n```\nvector<int> sortArrayByParityII(vector<int>& A) {\n  for (int i = 0, j = 0; i < A.size() && j < A.size(); ) swap(\n      *find_if(begin(A) + i, end(A), [&] (int v) { return (i++ % 2 == 0 && v % 2 != 0) || i == A.size(); }),\n      *find_if(begin(A) + j, end(A), [&] (int v) { return (j++ % 2 != 0 && v % 2 == 0) || j == A.size(); }));\n  return A;\n}\n```
[]