Given a sorted array of integers, return a new array containing the squares of each number in non-decreasing order. The sorted input allows a two-pointer merge-like approach from both ends.
nums = sorted array of integers
sorted array of squares
Example 1:
Input:
nums = [-4,-1,0,3,10]
Output:
[0,1,9,16,100]
Explanation:
Squaring breaks the original order, so the output must be rebuilt in sorted order.
Example 2:
Input:
nums = [-7,-3,2,3,11]
Output:
[4,9,9,49,121]
Explanation:
The squares are sorted after using the largest absolute value from either end.