I was reading Skiena's Algorithm Design Manual, and couldn't solve this problem.
Suppose an array A consists of n elements, each of which is red, white, or blue. We seek to sort the elements so that all the reds come before all the whites, which come before all the blues The only operation permitted on the keys are
Examine(A,i) { report the color of the ith element of A.
Swap(A,i,j) { swap the ith element of A with the jth element.
Find a correct and efficient algorithm for red-white-blue sorting. There is a linear-time solution.
I tried using quicksort, and on 3 pivots, I should be able to solve it, but I don't know what to do when I see duplicates in quick sort.