Search⌘ K
AI Features

Solution: Squares of a Sorted Array

Learn how to apply the two pointers technique to square each element of a sorted integer array and return a new sorted array of these squares. Understand the approach to optimize both time and space complexity by comparing absolute values from each end of the array and filling the result from right to left.

Statement

You are given an integer array, nums, sorted in non-decreasing order. Your task is to return a new array containing the squares of each number, also sorted in non-decreasing order.

Constraints:

  • 11 ...