Search⌘ K
AI Features

Solution: Squares of a Sorted Array

Understand how to apply the two-pointer approach to compute the squares of a sorted array and return a new array in sorted order. This lesson guides you through comparing absolute values with two pointers to fill the result in a single pass, achieving a linear time complexity solution.

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 ...