Search⌘ K
AI Features

Solution: Squares of a Sorted Array

Explore how to apply the two pointers pattern to efficiently return a new sorted array of squared values from an input sorted array. Learn to compare absolute values from both ends, fill the result in place, and achieve a linear time and constant extra space 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 ...