Search
⌘K

Leetcode 977. Squares of a Sorted Array

Given a non-decreasing integer array (which may contain negatives), return the squares of each number in non-decreasing order; the core challenge is to produce this in O(n) time by leveraging the input order (e.g., merging largest squares from both ends) instead of re-sorting.

Asked at:

Uber


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Mid April, 2026

Uber

Senior

Early April, 2026

Uber

Senior

Late March, 2026

Uber

Mid-level

Given an integer array nums sorted in non-decreasing order (may contain negative numbers), return a new array ans where ans[i] = nums[i]^2, and ans is also sorted in non-decreasing order. Follow up find kth smallest square in O(1) space.

Your account is free and you can post anonymously if you choose.