Search⌘ K
AI Features

Solution: Squares of a Sorted Array

Explore how to apply the two pointers pattern to transform a sorted array of integers into a sorted array of their squares. Learn to efficiently compare elements from both ends, fill the result array in a single pass, and understand the time and space efficiency of this approach.

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