Squares of a Sorted Array
Problem statement
Given an integer array nums sorted in nondecreasing order, return an array containing the square of every value, also sorted in nondecreasing order.
Function
sortedSquares(nums: int[]) → int[]Examples
Example 1
nums = [-4,-1,0,3,10]return = [0,1,9,16,100]Squaring gives [16,1,0,9,100], which sorts to the returned array.
Example 2
nums = [-7,-3,2,3,11]return = [4,9,9,49,121]The negative values contribute large squares from the left end.
Example 3
nums = []return = []An empty input has no squares.
Constraints
0 <= nums.length <= 100000.-10000 <= nums[i] <= 10000.numsis sorted in nondecreasing order.