# Leet Code 977: Squares of a Sorted Array

### Problem statement:

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

### Constraints

• 1 <= nums.length <= 104
• -104 <= nums[i] <= 104
• nums is sorted in non-decreasing order.

### Soultion:

`.css-1r5hp7i{position:absolute;top:0;right:0;z-index:1;border-radius:0 5px 0 5px;padding:0.25rem 0.6rem;border:none;cursor:pointer;background:#44475a;color:rgb(248, 248, 242);-webkit-transition:all 200ms ease;transition:all 200ms ease;font-size:12px;}.css-1r5hp7i:disabled{cursor:not-allowed;}.css-1r5hp7i:not(:disabled):hover,.css-1r5hp7i:not(:disabled):focus{background:#8257E6;}`/** * @param {number[]} nums * @return {number[]} */var sortedSquares = function(nums) {    let l = 0;    let r = nums.length-1;    let arr = [];    for(let i = nums.length-1; i>=0; i--) {        const ml = nums[l]*nums[l];        const mr = nums[r]*nums[r];        if(ml>mr) {            arr[i] = ml;            l++;        } else {            arr[i] = mr;            r--;        }    }    return arr;};``