FastPrepSorted Squares From an Ordered Array
Problems/Sorted Squares From an Ordered Array

Sorted Squares From an Ordered Array

Adobe logoAdobe● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: You square every value of an array that is already in order, and return the squares in order too. The report is by an anonymous fresher who interviewed for an Adobe MTS 1 role in March 2022 and was rejected. The first round was a 60-minute video call on 1 March 2022 with three problems. This was the last of them. The report gives it only by its common name. Under that name, the saved copy keeps a short summary of the task, cut off before its example. It has nothing from the author about the approach or code.

The rules are those of the named task. We chose these limits: 1 to 2000 values, from -10^4 to 10^4, with repeats allowed. We wrote new examples.

Our version is about 95% the same as the reported question.

Given an integer array nums sorted in non-decreasing order, return an array of the squares of its values, also sorted in non-decreasing order.

Negative values make this less simple than it looks: -6 is the smallest value but its square, 36, may be the largest. Equal squares all stay in the answer.

Function

sortedSquares(nums: int[]) → int[]

Examples

Example 1

nums = [-6,-2,1,3,5]return = [1,4,9,25,36]

The squares in the given order are 36, 4, 1, 9, 25. Sorted: [1,4,9,25,36].

Example 2

nums = [-8,-8,-3]return = [9,64,64]

All values are negative, so the squares come out largest first: 64, 64, 9. Sorted: [9,64,64]; the repeated value stays twice.

Example 3

nums = [0,2,2,7]return = [0,4,4,49]

The values are already non-negative, so squaring keeps the order: [0,4,4,49].

Constraints

  • 1 <= nums.length <= 2000
  • -10^4 <= nums[i] <= 10^4
  • nums is sorted in non-decreasing order.

Interview reports that mention this question

  • Adobe New Grad MTS Interview Questions: 7 Experiences

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
  • Adobe Product Intern Interviews: 15 Experiences (Part 3 of 4)
See Adobe hiring insights
Saved
class Solution {
    public int[] sortedSquares(int[] nums) {
        // Write your code here.
    }
}
Checking account…