Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Use two pointers from both ends. If left points to even, advance left. If right points to odd, retreat right. If left is odd and right is even, swap them. This is a simplified partition (like QuickSort) around the condition "is even".
The two-pointer partition ensures all even numbers migrate to the left portion and all odd numbers to the right. Each element is visited at most once from each side, giving O(n) time. This is the same partition logic used in QuickSort, simplified to a boolean condition.
Updated Feb 2026