A sensor emits n readings already sorted in non-decreasing order; readings may be negative. Report the squares of all readings, listed in non-decreasing order.
Line 1: an integer n.
Line 2: n non-decreasing integers, the readings.
One line: the n squared readings in non-decreasing order, space-separated.
Example 1
Input
5 -4 -1 0 3 5
Expected
0 1 9 16 25
Explanation
Squares are 16, 1, 0, 9, 25; sorted ascending that is 0 1 9 16 25.
Example 2
Input
3 -7 -3 -1
Expected
1 9 49
Explanation
All readings are negative, so squaring reverses their order: 1 9 49.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →