Search⌘ K
AI Features

Solution: Squares of a Sorted Array

Explore how to apply the two pointers technique to solve the problem of squaring and sorting a non-decreasing integer array efficiently. Understand the step-by-step approach to compare values from both ends, place squared values in order, and optimize time and space complexity.

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 \leq nums.length 103\leq 10^3 ...