dsa · easy

Squares of a Sorted Array

ArrayTwo Pointers

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

Arguments

**Example 1:** `` Input: nums = [-4,-1,0,3,10] Output: [0,1,9,16,100] ``

Constraints

1 <= nums.length <= 4*10^4 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[-4,-1,0,3,10]

Expected:
[0,1,9,16,100]

Example 2

Input:
[-7,-3,2,3,11]

Expected:
[4,9,9,49,121]

Open in the Dojo editor