Counting Sort Problem Statement
Ninja is learning about sorting algorithms, specifically those that do not rely on comparisons. Can you help Ninja implement the counting sort algorithm?
Example:
Input:
ARR = {-2, 1, 2, -1, 0}
Output:
{-2, -1, 0, 1, 2}
Explanation:
The array is sorted in increasing order using counting sort.
Input:
The first line contains an integer 'T' which denotes the number of test cases.
The first line of each test case contains an integer ‘N’ representing the length of the ‘ARR’ array.
The second line of each test case contains ‘N’ space-separated integers representing the ‘ARR’ array.
Output:
For each test case, print the sorted array.
The output of each test case will be printed in a separate line.
Constraints:
- 1 <= T <= 10
- 1 <= N <= 5000
- -10^4 <= ARR[i] <= 10^4
- Time limit: 1 sec
Note:
You do not need to input or print anything, as it has already been taken care of. Just implement the given function.

AnswerBot
4mo
Implement counting sort algorithm to sort an array of integers without comparisons.
Count the frequency of each element in the input array.
Calculate the prefix sum of frequencies to determine the posit...read more
Help your peers!
Add answer anonymously...
PayPal Software Developer interview questions & answers
A Software Developer was asked 7mo agoQ. Given a list and a series of queries, how would you efficiently sort the list af...read more
A Software Developer was asked Q. Given an array of numbers, find a subset of numbers that sum to zero.
A Software Developer was asked Q. Explain how BFS works.
Popular interview questions of Software Developer
A Software Developer was asked 7mo agoQ1. Given a list and a series of queries, how would you efficiently sort the list af...read more
A Software Developer was asked Q2. Given an array of numbers, find a subset of numbers that sum to zero.
A Software Developer was asked Q3. Explain how BFS works.
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

