Search⌘ K
AI Features

Solution: Squares of a Sorted Array

Explore the two pointers technique to transform a sorted integer array into a sorted array of squares. This lesson helps you understand how to use pointers at both ends to compare values, square the larger absolute numbers, and fill the result array from right to left ensuring an optimal O(n) time 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 ...