Group three colors in one pass
colors holds only the values 0, 1 and 2 (think red, white and blue). Rearrange it in place so every 0 comes first, then every 1, then every 2, and return the same list.
Make a single pass that swaps values into place with O(1) extra space: no sort function, and no counting the values first to rewrite the list.
Examples
sort_colors([2,0,1,2,1,0])→[0,0,1,1,2,2]sort_colors([1,2,0])→[0,1,2]sort_colors([2,2,1,1,0,0])→[0,0,1,1,2,2]