Search⌘ K
AI Features

Solution: Squares of a Sorted Array

Discover how to apply the two pointers technique to efficiently square a sorted integer array and return a sorted array of squares. This lesson helps you understand the logic behind comparing absolute values from both ends, filling the result array from right to left for an optimal O(n) time and O(1) 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 ...