Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.

&nbsp;
Example 1:

Input: nums = [-4,-1,0,3,10]
Output: [0,1,9,16,100]
Explanation: After squaring, the array becomes [16,1,0,9,100].
After sorting, it becomes [0,1,9,16,100].


Example 2:

Input: nums = [-7,-3,2,3,11]
Output: [4,9,9,49,121]


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 104
	-104 &lt;= nums[i] &lt;= 104
	nums is sorted in non-decreasing order.


&nbsp;
Follow up: Squaring each element and sorting the new array is very trivial, could you find an O(n) solution using a different approach?
class Solution:
    def sortedSquares(self, nums: List[int]) -> List[int]:
        l,r = 0, len(nums)-1
        pointer = 0
        arr = [0] *len(nums)
        pointer = r
        while l<=r:
            if abs(nums[r]) > abs(nums[l]):
                arr[pointer] = nums[r] **2
                r-=1
                pointer-=1
            else:
                arr[pointer] = nums[l] **2
                l+=1
                pointer-=1
                
            
        return arr
            
            
            
class Solution {
    public int[] sortedSquares(int[] nums) {
        int s=0;
        int e=nums.length-1;
        int p=nums.length-1;
        int[] a=new int[nums.length];
        while(s<=e){
            if(nums[s]*nums[s]>nums[e]*nums[e]){
                a[p--]=nums[s]*nums[s];
                s++;
            }
            else{
                a[p--]=nums[e]*nums[e];
                e--;
            }
        }
        return a;
    }
}
class Solution {
public:
    vector<int> sortedSquares(vector<int>& nums) {
        for(int i=0;i<nums.size();i++){
            nums[i] = nums[i]*nums[i];
        }
        sort(nums.begin(),nums.end());
        return nums;
    }
};
var sortedSquares = function(nums) {
	let left = 0;
	let right = nums.length - 1;
	const arr = new Array(nums.length);
	let arrIndex = arr.length - 1;

	while (left <= right) {
		if (Math.abs(nums[left]) > Math.abs(nums[right])) {
			arr[arrIndex] = nums[left] * nums[left];
			left++;
		} else {
			arr[arrIndex] = nums[right] * nums[right];
			right--;
		}
		arrIndex--;
	}

	return arr;
};
Squares of a Sorted Array