Problem of the day
Input:
βARRβ = [-6,-3, 2, 1, 5]
If we take a square of each element then the array/list will become [36, 9, 4, 1, 25].
Then the sorted array/list will be [1, 4, 9, 25, 36].
Output :
[1, 4, 9, 25, 36].
The first line of input contains a single integer βTβ, representing the number of test cases.
Then the βTβ test cases follow.
The first line of each test case contains a single integer βNβ denoting the size of βARRβ.
The second line contains βNβ space-separated distinct integers denoting the array elements.
For each test case, print the array elements separated by a single space.
The output of every test case will be printed in a separate line.
You donβt have to print anything, it has already been taken care of. Just implement the given function.
1 <= T <=100
1 <= N <= 10^4
-10^4 <= βARR[i]β <= 10^4
Where 'ARR[i]' denotes the value of 'ARR' at index 'i'.
Time limit: 1 sec
2
4
-3 -3 1 2
6
0 1 2 3 4 5
1 4 9 9
0 1 4 9 16 25
For test case 1:
On taking the square of each element βARRβ will become [9, 9, 1, 4].
Now we can sort the array/list and output will be [1, 4, 9, 9].
For test case 2:
On taking the square of each element βARRβ will become [0, 1, 4, 9, 16, 25].
Now we can see that the array/list is already sorted, so the output will be [0, 1, 4, 9, 16, 25].
2
1
5
4
-6 -3 -2 -1
25
1 4 9 36
For test case 1:
On taking the square of each element βARRβ will become [25].
Now as the array/list has only 1 element so it is already sorted, the output will be [25].
For test case 2:
On taking the square of each element βARRβ will become [36,9,4,1].
Now we can see that the array/list is already sorted, so the output will be [36, 9, 4, 1].