FastPrepSorted Squares in Descending Order
Problems/Sorted Squares in Descending Order

Sorted Squares in Descending Order

WhatNot logoWhatNot● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The engineering interview recollection asks you to square one sorted array and return it from highest to lowest, and notes that the recall is imperfect. Our version is about 90% the same as the reported question. Signed integers, ascending input, duplicates, empty input, and limits are our assumptions.

Given an integer array nums sorted from smallest to largest, return the square of every element from highest to lowest.

Values may be negative. Preserve duplicate occurrences. Return an empty array when nums is empty.

Try to achieve O(nums.length) time by using the sorted input.

Function

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

Examples

Example 1

nums = [-4,-1,0,3,10]return = [100,16,9,1,0]

The squares [16,1,0,9,100] become [100,16,9,1,0] in highest-to-lowest order.

Example 2

nums = [-3,-1,2]return = [9,4,1]

The negative value -3 produces the largest square.

Example 3

nums = [-2,0,2]return = [4,4,0]

Both entries with magnitude 2 contribute 4.

Constraints

  • 0 <= nums.length <= 5000.
  • nums is sorted in nondecreasing order.
  • -10000 <= nums[i] <= 10000.

More WhatNot Phone Screen questions

  • Merge Sorted Squares of Two ArraysPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Adjacent Pair and Run RemovalPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • User Journey Paths from a Log StreamPHONE SCREEN · Seen Nov 2026
  • Reachable Exits in an Obstacle GridPHONE SCREEN · Seen Oct 2026
  • Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
  • Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
  • Earliest Car for Each PassengerPHONE SCREEN · Seen Sep 2026
  • Minimum Stores for a Shopping ListPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Squares of a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
  • Assign CookiesAmazon · PHONE SCREEN
  • Merge Two Sorted ArraysCapgemini · PHONE SCREENCapgemini interview questions
  • Squares of a Sorted ArrayStryker · PHONE SCREEN
  • Squares of a Sorted ArrayGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Merge Into the Zero-Padded ArrayAdobe · PHONE SCREENAdobe interview questions
  • Three Partition ArrayMicrosoft · PHONE SCREENMicrosoft interview questions
  • Assign CookiesExpedia · PHONE SCREEN · ONSITE INTERVIEWExpedia interview questions
  • Merge Two Sorted ArraysZillow · PHONE SCREENZillow interview questions
  • Merge Sorted Arrays with DuplicatesMygate · PHONE SCREENMygate interview questions

Interview reports that mention this question

  • Whatnot interviews · May 2026

WhatNot interview experiences

  • Whatnot OA · 2024
  • Whatnot OA · November 2023
  • Whatnot interviews · November 2023
  • Whatnot interviews · February 2024
  • Whatnot interviews · March 2024
All WhatNot interview questionsSee WhatNot hiring insights
Saved
class Solution {
    public int[] descendingSquares(int[] nums) {
        // write your code here
    }
}
Checking account…