Close
Topic list
Sort 0 1 2
EASY
22 mins
Sorting
Arrays
Topics (Covered in this problem)
Problem solved
Skill meter
Sorting
-
Arrays
-
Other topics
Problem solved
Skill meter
Strings
-
Matrices (2D Arrays)
-
Binary Search
-
-
Stacks & Queues
-
Trees
-
Graph
-
Dynamic Programming
-
Greedy
-
Tries
-
Binary Search Trees
-
Heap
-
Bit Manipulation
-

# Sort 0 1 2

Contributed by
Ashwani
Easy
Avg time to solve 22 mins
Share

## Problem Statement

#### You have been given an integer array/list(ARR) of size 'N'. It only contains 0s, 1s and 2s. Write a solution to sort this array/list.

##### Note :
``````Try to solve the problem in 'Single Scan'. ' Single Scan' refers to iterating over the array/list just once or to put it in other words, you will be visiting each element in the array/list just once.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1 :
``````2
6
0 1 2 2 1 0
7
0 1 2 1 2 1 2
``````
##### Sample Output 1 :
``````0 0 1 1 2 2
0 1 1 1 2 2 2
``````
##### Sample Input 2 :
``````2
7
2 2 2 1 1 1 0
6
2 1 2 0 1 0
``````
##### Sample Output 2 :
``````0 1 1 1 2 2 2
0 0 1 1 2 2
``````
Console