Sort Array of 0s, 1s and 2s (Dutch National Flag)
M · mediumPracticearraystwo-pointer
Problem
Sort an array containing only 0s, 1s and 2s in a single traversal without extra space.
Example
Input
6 0 1 2 1 0 2
Output
0 0 1 1 2 2
Three pointers: low=0, mid=0, high=n-1. Swap based on value at arr[mid].