Sort Array by Parity II (Java)
Intuition\nThe intuition behind this approach is to use two pointers, one for even indices and another for odd indices, to place even and odd numbers at their r
# Intuition\n**The intuition behind this approach is to use two pointers, one for even indices and another for odd indices, to place even and odd numbers at their respective positions in the result array. The goal is to satisfy the condition that whenever nums[i] is odd, i is odd, and whenever nums[i] is even, i is even.**\n\n# Approach\n*Initialize evenIndex to 0 and oddIndex to 1.\nIterate through the array, and for each element:\nIf it is even, place it at the evenIndex position and increment evenIndex by 2.\nIf it is odd, place it at the oddIndex position and increment oddIndex by 2.\nReturn the modified array result.*\n\n# Complexity\n### - Time complexity: O(n)\n\n### - Space complexity: O(n)\n\n# Code\n```\nclass Solution {\n    public int[] sortArrayByParityII(int[] nums) {\n        int len = nums.length;\n        int[] result = new int[len];\n\n        int evenIndex = 0;\n        int oddIndex = 1;\n\n        for (int num : nums) {\n            if (num % 2 == 0) {\n                result[evenIndex] = num;\n                evenIndex += 2;\n            } else {\n                result[oddIndex] = num;\n                oddIndex += 2;\n            }\n        }\n        return result;\n    }\n}\n```
['Array', 'Math', 'Two Pointers', 'Sorting', 'Java']