Merge the Sorted Squares of Two Sorted Arrays
Company: Whatnot
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: Merge squared values from two sorted arrays in linear time, including negative inputs, duplicate preservation, endpoint comparisons, and overflow handling.
Read the full Whatnot Software Engineer interview experience this question came from
Constraints
- The combined input length is at most 2^31 − 1.
- Each input is an integer whose absolute value is at most floor(sqrt(2^53 − 1)), so each square is an exact JSON integer.
Examples
Input: ([0, 1, 4], [2, 3, 3])
Expected Output: [0, 1, 4, 9, 9, 16]
Explanation: The repeated 3 contributes two copies of 9.
Input: ([-5, -2, 3], [-4, 0, 2])
Expected Output: [0, 4, 4, 9, 16, 25]
Explanation: Negative values can produce both the largest square and ties.
Hints
- Two values with opposite signs and the same magnitude contribute equal squares.