Sort the Flag
The array contains only 0s, 1s and 2s. Print it sorted — ideally in ONE pass without a sorting routine (Dutch national flag).
Input: the first line has N; the second line has N values from {0, 1, 2}.
Output: the sorted values.
Constraints:
- 1 ≤ N ≤ 105
Sample Tests
Input 1
6 2 0 1 2 0 1
Output 1
0 0 1 1 2 2
Input 2
1 1
Output 2
1
Discussion (opens after you solve — no spoilers before)
No comments yet.