Loading...
Loading...
Loading...
Tickets have priority 0, 1 or 2. Print them grouped with all 0 first, then all 1, then all 2, in a single pass over the data with constant extra space (three pointers).
Example 1
Input
2 0 2 1 1 0
Output
0 0 1 1 2 2
Example 2
Input
1
Output
1
Try the problem first. Open one hint at a time.
Keep three pointers: low, mid and high.
After swapping with high, do not move mid; the new value there is unchecked.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor