javascript O(n) time and O(1) space complexity with explanation
The idea is to have two pointers, one for looping through the array, and the other one is to track the index of the \'first-encountered\' odd value in the array
The idea is to have two pointers, one for looping through the array, and the other one is to track the index of the \'first-encountered\' odd value in the array. \nSo, when we loop through the array, if the element is even, we will swap with that current \'first-encountered\' odd value (in order to **bubble** that even element up), and we update the odd-tracking index by 1.\nThe solution to this problem is similar to that of the "Move Zeroes" problem (https://leetcode.com/problems/move-zeroes/).\nPlease upvote if this helps :)\n\n```\nvar sortArrayByParity = function(nums) {\n    let oddIdx = 0;\n    \n    for (let i = 0; i < nums.length; i++) {\n        if (nums[i] % 2 === 0) {\n            [nums[i], nums[oddIdx]] = [nums[oddIdx], nums[i]];\n            oddIdx++;\n        }\n    }\n    \n    return nums;\n};\n```
['Two Pointers', 'JavaScript']