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 consisting of 0, 1, and 2 in non-decreasing order.
Use a counting sort approach to count the occurrences of 0s, 1s, and 2s in the array.
Update the array with the coun...read more
Help your peers!
Add answer anonymously...
Cybage React Developer interview questions & answers
A React Developer was asked Q. How is state changed in Redux?
A React Developer was asked Q. What are callbacks in JavaScript?
A React Developer was asked Q. How can we structure the top-level directories in Redux?
Popular interview questions of React Developer
A React Developer was asked Q1. How is state changed in Redux?
A React Developer was asked Q2. What are callbacks in JavaScript?
A React Developer was asked Q3. How can we structure the top-level directories in Redux?
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

