13. Sorting Colors

Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively:

let sequence = [2,0,2,1,1,0] -> [0, 0, 1, 1, 2, 2]

Hints

If not done correctly, sorting data can be one of the most expensive aspects of any program or application. While standard production sorting algorithms run in O(n log n) time, the average / worst case runtimes often produce a O(n) squared result. Is there a more efficient technique or algorithm you could augment to sort the color sequence?