Sort Array Problem Statement
Given an array consisting of 'N' positive integers where each integer is either 0, 1, or 2, your task is to sort the given array in non-decreasing order.
Input:
Each input starts with an integer T, the number of test cases. For each test case, the first line contains an integer N, the size of the array. The second line contains N space-separated integers which are elements of the array.
Output:
For each test case, output the sorted array of N integers in a separate line.
Example:
Input:
2
5
0 2 1 2 0
3
2 1 0
Output:
0 0 1 2 2
0 1 2
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 10^4
0 ≤ arr[i] ≤ 2
, where arr[i] is the array element at index 'i'.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.

AnswerBot
4mo
Sort an array of 0s, 1s, and 2s in non-decreasing order.
Use a counting sort algorithm to count the occurrences of 0s, 1s, and 2s in the array.
Then reconstruct the array by placing the counted elements...read more
Help your peers!
Add answer anonymously...
Amdocs Front end Developer interview questions & answers
A Front end Developer was asked Q. What are callbacks in JavaScript?
A Front end Developer was asked Q. Can you explain promises and their three states?
A Front end Developer was asked Q. What is the Same-origin policy?
Popular interview questions of Front end Developer
A Front end Developer was asked Q1. What are callbacks in JavaScript?
A Front end Developer was asked Q2. Can you explain promises and their three states?
A Front end Developer was asked Q3. What is the Same-origin policy?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

