406. Squares of a Sorted Array
EasyTwo Pointers
The array is sorted (it may contain negatives). Print the squares of its elements in non-decreasing order.
Input format
Line 1: n Line 2: n sorted integers
Output format
The sorted squares.
Example 1
Input
5 -4 -1 0 3 10
Output
0 1 9 16 100
Example 2
Input
5 -7 -3 2 3 11
Output
4 9 9 49 121
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…