nums is sorted in increasing order and may contain negative numbers. Return the square of each number, also sorted in increasing order, in O(n) time (sorting the squares works but takes O(n log n)).
For [-4, -1, 0, 3, 10] the answer is [0, 1, 9, 16, 100].
Example 1
Input:
sorted_squares([-4, -1, 0, 3, 10])
Output:
[0, 1, 9, 16, 100]
Example 2
Input:
sorted_squares([-7, -3, 2, 3, 11])
Output:
[4, 9, 9, 49, 121]
0 <= len(nums) <= 200000-10**4 <= nums[i] <= 10**4nums is sorted in increasing order.No results yet
Run your code to check it against the examples, or submit to run every test.