Basic partition
Input
nums = [3, 1, 2, 4, 7, 6]
Output
[6, 4, 2, 1, 7, 3]
A two-pointer partition swaps odd numbers on the left with even numbers on the right. Evens (6,4,2) appear before odds (1,7,3).
Full lesson preview
Partition an integer list in-place so that all even numbers appear before odd numbers using a two-pointer approach.
Problem statement
Task
Examples
Input
nums = [3, 1, 2, 4, 7, 6]
Output
[6, 4, 2, 1, 7, 3]
A two-pointer partition swaps odd numbers on the left with even numbers on the right. Evens (6,4,2) appear before odds (1,7,3).
Input format
Output format
Constraints
Samples
Input
[2, 4, 6]
Output
[2, 4, 6]
All elements are even; the list remains the same.