solve(nums) — nums is sorted in non-decreasing order and may contain negative
numbers. Return the squares of every value, also sorted in non-decreasing order.
Sorting the squares works in O(n log n), but the input order gives you more: the
largest square is always at one of the two ends. Walk two pointers inward and fill
the result from the back in O(n).
Examples
solve([-4,-1,0,3,10]) → [0,1,9,16,100]
solve([-7,-3,2,3,11]) → [4,9,9,49,121]
solve([-5,-3,-1]) → [1,9,25]Sample tests