Problems > Evens First, Order Kept > Editorial

Evens First, Order Kept — Solution & Editorial

Back to the Problem

Two passes (evens then odds) — a stable partition. In-place swapping breaks stability; concatenation keeps it.

Complexity: O(N)

Watch out: Note (−3) % 2 is −1 in C++/Java — test oddness with x % 2 != 0, not x % 2 == 1.