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 positive integers (0, 1, 2) in non-decreasing order.
Use counting sort algorithm to sort the array efficiently.
Count the occurrences of 0s, 1s, and 2s in the array.
Update the array wit...read more
Help your peers!
Add answer anonymously...
Siemens Front end Developer interview questions & answers
A Front end Developer was asked Q. What are closures in JavaScript?
A Front end Developer was asked Q. What is prototype chaining in JavaScript?
A Front end Developer was asked Q. What are the features of HTML5?
Popular interview questions of Front end Developer
A Front end Developer was asked Q1. What are closures in JavaScript?
A Front end Developer was asked Q2. What is prototype chaining in JavaScript?
A Front end Developer was asked Q3. What are the features of HTML5?
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

