Square sorted array

Easy

Given an array of numbers, return an array that contains the squares of all the numbers in non-decreasing order.

Example
Array: [6, -8, 3, -1, 4]
Answer: [1, 9, 16, 36, 64]

Testing

Input Format

The first line contains 'T' denoting the no. of test cases.

T lines each contain a number 'n' denoting the number of elements, followed by n space-separated numbers denoting the array elements.

Output Format

T lines each contain n numbers denoting the sorted square array.

Sample Input

2
4 -3 1 2 4
5 6 -8 3 -1 4

Expected Output

1 4 9 16
1 9 16 36 64

Constraints

0 <= T <= 100

1 <= N <= 1000

-1000 <= value of array element <= 1000

Companies
Editorial Link: Editorial