Search⌘ K
AI Features

Solution: Squares of a Sorted Array

Understand how to apply the two pointers technique to square elements of a sorted array and produce a sorted result efficiently. This lesson helps you implement an optimized linear time algorithm by comparing absolute values from both ends and filling a result array 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 ...