Sort Colors
Practice this coding question on Coding Gurukul.
Problem statement
A warehouse labels parcels 0, 1, or 2 for three dispatch zones. Rearrange the labels into ascending order in place. Use constant extra space and aim for one pass without a library sorting function.
Input format
First line: n. Second line: n space-separated integers.
Output format
Print all labels in sorted order.
Constraints
1 <= n <= 100000; each label is 0, 1, or 2.
Sample input
7 2 1 0 2 0 1 2
Sample output
0 0 1 1 2 2 2
Sign in to run or submit a solution in C++, Java or Python.