SDE Path

Sort an Array of 0s 1s and 2s (Dutch Flag)

Medium

Sort an Array of 0s 1s and 2s (Dutch Flag)

Sort an array containing only three distinct values in a single pass using three pointers.

Input format

The first line contains N. The second line contains N integers, each 0, 1, or 2.

Output format

Print the array sorted in non-decreasing order, space-separated on one line.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
6
2 0 2 1 1 0
Expected output
0 0 1 1 2 2
Example 2
Input
1
1
Expected output
1