Trains the technique from
LeetCode 905Sort Array By ParityThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A list of whole numbers reads values.
Return the list rearranged so that every even value comes before every odd one, with the even values keeping the order they had among themselves and the odd values likewise keeping theirs.
Example 1
The evens are 2 and 4 in that order, and the odds are 1 and 3 in that order, so the evens go first with each group's order untouched.
Example 2
The only even value moves to the front and the two odd sevens follow in the order they were in.
Example 3
A single odd value has nothing to move ahead of it.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def sort_array_by_parity(values: list[int]) -> list[int]:public int[] sortArrayByParity(int[] values)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.