readings, already sorted in non-decreasing order; some of them may be negative. The report needs their squares.
Return the squares of all numbers in readings, sorted in non-decreasing order.
Squaring everything and sorting is easy. Try to do it in O(n) without sorting.readings=[-6, -2, 1, 5] → [1, 4, 25, 36]
The squares are 36, 4, 1, 25; in ascending order that is 1, 4, 25, 36.
readings=[-3, -3, 0, 3] → [0, 9, 9, 9]
Equal squares all stay in the answer: three 9s.
readings=[2, 8] → [4, 64]
readings is sorted in non-decreasing orderreadings=[-6, -2, 1, 5]
[1, 4, 25, 36]
Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.