Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Squares of a Sorted Array

XPChallenge Points: 10
levelLevel: Easy

You are given an array nums that is already sorted in non-decreasing order.
Your task is to compute the square of each element and return a new array where these squared values are also arranged in non-decreasing order.

Example 1:

Input: nums = [-5, -2, 1, 4]

Output: [1, 4, 16, 25]

Explanation:

Squaring gives [25, 4, 1, 16]. Sorting results in [1, 4, 16, 25].

Example 2:

Input: nums = [-8, -3, 0, 2, 5]

Output: [0, 4, 9, 25, 64]

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result