FastPrepMerge Sorted Squares of Two Arrays
Problems/Merge Sorted Squares of Two Arrays

Merge Sorted Squares of Two Arrays

WhatNot logoWhatNot● MediumFULLTIMENEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Senior engineering reports describe merging two sorted arrays by squared value. One explicitly requires squared output and includes negative numbers. Our version is about 95% the same as the reported question. Ascending order, repeated values, empty inputs, and limits complete our version.

Given two integer arrays a and b, each sorted from smallest to largest, return one array containing the square of every element from both arrays, sorted from smallest to largest.

Negative values are allowed. Keep one result for every input element, including repeated values and equal squares. Either or both arrays may be empty.

Can you solve the task in O(a.length + b.length) time without sorting the squared values?

Function

mergeSortedSquares(a: int[], b: int[]) → int[]

Examples

Example 1

a = [1,3,7]b = [4,10,11]return = [1,9,16,49,100,121]

Squaring the two reported inputs gives [1,9,49] and [16,100,121]; merging gives the displayed order.

Example 2

a = [-4,-1,0,3]b = [-2,2]return = [0,1,4,4,9,16]

Both -2 and 2 contribute 4.

Example 3

a = []b = [0,5]return = [0,25]

An empty first input contributes no elements.

Constraints

  • 0 <= a.length + b.length <= 5000.
  • Both arrays are sorted in nondecreasing order.
  • -10000 <= a[i], b[i] <= 10000.

More WhatNot Phone Screen questions

  • 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
  • Knight Dialer SequencesPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • 3SumAmazon · PHONE SCREEN
  • 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
  • Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
  • Find All Pythagorean TripletsDell Technologies · PHONE SCREENDell Technologies interview questions
  • Meeting Rooms IIUber · PHONE SCREENUber interview questions
  • Sort a Quadratic-Transformed ArrayLinkedIn · PHONE SCREENLinkedIn interview questions
  • Count Triplets With Sum at Most TargetGoogle · ONSITE INTERVIEWGoogle interview questions
  • Sort ColorsCapital One · ONSITE INTERVIEWCapital One interview questions
  • 3SumOptimus Information · ONSITE INTERVIEWOptimus Information interview questions

Interview reports that mention this question

  • Whatnot interviews · June 2025
  • Whatnot interviews · May 2026
  • Whatnot interviews · April 2026
  • Whatnot interviews · June 2026
  • Whatnot interviews · December 2023
  • Whatnot interviews · October 2025
All WhatNot interview questionsSee WhatNot hiring insights
Saved
class Solution {
    public int[] mergeSortedSquares(int[] a, int[] b) {
        // write your code here
    }
}
Checking account…