


Input: 'arr' = [2, 2, 2, 2, 0, 0, 1, 0]
Output: Final 'arr' = [0, 0, 0, 1, 2, 2, 2, 2]
Explanation: The array is sorted in increasing order.
The first line contains a positive integer ‘n’, which represents the length of the array/list.
The second line of each test case contains ‘n’ single space-separated integers representing the elements of the array/list.
The output will print ‘n’ single space-separated integers of the sorted array/list.
You do not need to print anything; it has already been taken care of. Just implement the given function.
Simply, we will sort the array.
A two-pass algorithm can easily solve the problem. We will count the number of 0s, 1s and 2s in the array/list.
Then, we will overwrite the array with the total number of 0s, followed by 1s and 2s, respectively.
We can sort the array in one-pass by maintaining three positional pointers ‘zeroPos’, ‘onePos’ and ‘twoPos’ initialised to 0, 0 and n - 1, respectively.
Here, ‘zeroPos’ represents the first 1 after all 0s, ‘onePos’ represents the current element, and ‘twoPos’ represents the last unexplored element before all 2s.
Now, we iterate through ARR with ‘onePos’-