To solve this problem, you'll have to open it on the computer

Sort 0s 1s 2s

Arrays
easy
Score: 20

Given an array arr of size n containing only 0s, 1s, and 2s. Sort the array in ascending order. Complete the function, without using library’s sort function.

Input Format

First parameter - number n.

Second parameter - array arr of size n.

Output Format

Return the array of numbers.

Example 1:

Input: 
    5
    0 2 1 2 0
Output:
    0 0 1 2 2
Explanation:
    0s 1s and 2s are segregated into ascending order.    

Example 2:

Input: 
    3
    0 1 0
Output:
    0 0 1
Explanation:
    0s 1s and 2s are segregated into ascending order.

Constraints:

  • 1 <= N <= 1000000
  • 0 <= A[i] <= 2
  • Expected Time Complexity: O(N)
  • Expected Auxiliary Space: O(1)
Submit code to see the your result here