#C7180. Sorted Squares Transformation
Sorted Squares Transformation
Sorted Squares Transformation
Given a sorted array of integers, your task is to compute a new array where each element is the square of the corresponding element from the input array, and then sort the new array in non-decreasing order. In other words, for an input array ( A = [a_1, a_2, \ldots, a_n] ) (with ( a_1 \leq a_2 \leq \cdots \leq a_n )), you need to output the array ( B = [a_1^2, a_2^2, \ldots, a_n^2] ) sorted in ascending order.
Note that even if the input array contains negative numbers, after squaring they might become larger than some squares of positive numbers, so careful handling with a two-pointer approach is recommended.
inputFormat
The input is given via standard input (stdin) in the following format:
- The first line contains a single integer ( n ) representing the number of elements in the array.
- The second line contains ( n ) space-separated integers representing the sorted array.
outputFormat
Output a single line to standard output (stdout) containing ( n ) space-separated integers which form the sorted array of squared values.## sample
5
-4 -1 0 3 10
0 1 9 16 100
</p>