ArrayTwo PointersSorting
Given an array sorted in non-decreasing order, return the squares of each number, also sorted in non-decreasing order. Try to do better than squaring everything and sorting again.
Input
Line 1: n. Line 2: n integers in non-decreasing order.
Output
Print the sorted squares on one line.
Constraints
1 <= n <= 10^5 -10^4 <= each value <= 10^4
Example 1
Input
5 -4 -1 0 3 10
Output
0 1 9 16 100
Squares are 16, 1, 0, 9, 100, which sort to 0 1 9 16 100.