Mix of even and odd
Input
partition_by_parity([3, 1, 2, 4])
Output
[4, 2, 1, 3]
One valid partition places even numbers 4 and 2 before odd numbers; order inside groups is not required to be preserved.
Full lesson preview
Reorder an array so that all even numbers appear before odd numbers using an in-place approach.
Problem statement
Task
Examples
Input
partition_by_parity([3, 1, 2, 4])
Output
[4, 2, 1, 3]
One valid partition places even numbers 4 and 2 before odd numbers; order inside groups is not required to be preserved.
Input format
Output format
Constraints
Samples
Input
[2, 4, 6, 1, 3]
Output
[2, 4, 6, 1, 3]
Already partitioned with evens first; function may leave it unchanged.