The array nums has n objects, and each object has one of the three colours of the Indian flag: saffron, white or green. The numbers 0, 1 and 2 stand for saffron, white and green.
Sort the array in place so that all objects of the same colour are next to each other, in the order saffron, white, green (that is 0s first, then 1s, then 2s).
Solve it without using the sort function of your language.
Examples
Example 1:
Input: nums = [1,2,0,1,2,0,0]
Output: [0,0,0,1,1,2,2]
Explanation: The three 0s come first, then the two 1s, then the two 2s.
Example 2:
Input: nums = [2,2,1]
Output: [1,2,2]
Explanation: The 1 comes before the 2s.
Example 3:
Input: nums = [1]
Output: [1]
Explanation: One object is already sorted.