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.

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.

Late February, 2026

Uber

Senior

There was a follow up question as well. find the Kth smallest square for the same sorted array.

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