easyArraysPattern: Two Pointers
Symmetric Parity Partition Solution
Problem Statement
Given an array of integers, rearrange the elements such that all even integers occupy the prefix of the array and all odd integers occupy the suffix. You must perform this rearrangement in-place using the two-pointer technique. The relative order of the even and odd integers does not need to be preserved.
Examples
Example 1:
Input:[3, 1, 2, 4]
Output:[4, 2, 1, 3]
Explanation: After swapping, 4 and 2 are moved to the front, and 1 and 3 are moved to the back.
Example 2:
Input:[0, 7, 8, 5, 2]
Output:[0, 2, 8, 5, 7]
Explanation: All even numbers (0, 8, 2) are moved to the left, and all odd numbers (7, 5) are moved to the right.
Constraints
- 1 <= array.length <= 10^4
- 0 <= array[i] <= 10^4
Time: O(n) Space: O(1)
Master coding challenges related to Arrays and solve the Symmetric Parity Partition problem optimally.
Run, Test & Submit Code
Ready to practice this challenge? Launch our interactive compilation environment with compiler validation.
Solve on Interactive WorkspaceTested Solutions
No solution code is currently loaded.
Complete this code in the workspace editor.
