#K79237. Sorted Squares of a Sorted Array
Sorted Squares of a Sorted Array
Sorted Squares of a Sorted Array
Given a sorted array of integers, your task is to compute and output a sorted array where each element is the square of the corresponding input element. In other words, for each element (x), compute (x^2) and then sort the resulting values in non-decreasing order.
For example, if the input array is [-4, -1, 0, 3, 10], the output should be [0, 1, 9, 16, 100].
inputFormat
Input is given via standard input (stdin).
The first line contains an integer (n) representing the number of elements in the array. The second line contains (n) space-separated integers sorted in non-decreasing order.
outputFormat
Output the squared values of the input array, sorted in non-decreasing order, as a single line of space-separated integers to standard output (stdout).## sample
5
-4 -1 0 3 10
0 1 9 16 100
</p>