Efficiently sorting numbers in range from 0 to n^2 - 1
Submissions: 1188   Accuracy:

49.02%

  Difficulty: Easy   Marks: 2

Given an array of numbers of size n. It is also given that the array elements are in range from 0 to n2 – 1. Sort the given array in linear time.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer n denoting the size of the array. The following line contains n space separated integers.

Output:
Sort the given array in linear time.

Constraints:
1<=T<=10^5
1<=n<=10^4
1<=a[i]<=(10^4)-1

Example:
Input:

2
7
40 12 45 32 33 1 22
5
24 12 0 15 8

Output:
1 12 22 32 33 40 45
0 8 12 15 24

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Ayush Govil
Author: Ayush Govil 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.