less than 1 minute read

Given a list of integers sorted in ascending order nums, square the elements and give the output in sorted order.

Constraints

  • n ≤ 100,000 where n is the length of nums

https://binarysearch.com/problems/Square-of-a-List

Examples

Example 1

Input

  • nums = [-9, -2, 0, 2, 3]

Output

  • answer = [0, 4, 4, 9, 81]

Example 2

Input

  • nums = [1, 2, 3, 4, 5]

Output

  • answer = [1, 4, 9, 16, 25]

Solution

Leave a comment