Squares of a Sorted Array

Easy · Arrays & Strings · about 10 minutes

Asked at Meta, Amazon, Google, Uber, Instacart, Bloomberg, Swiggy.

nums is sorted ascending and may contain negatives. Square every element and return the squares, also in ascending order. Can you avoid a re-sort and finish in O(n)?

Related guides