Stable partition by parity

Write codeMedium15 min

Your task

Given an integer array a, return a new array with all even numbers first, then all odd numbers, where the relative order within the evens and within the odds is preserved (stable partition by parity). The array may be empty.

Examples

stable_partition_even_first(a: list[int]) -> list[int]
Example 1
Inputstable_partition_even_first([3, 1, 2, 4])
Output[2, 4, 3, 1]