← Whatnot Interview Insights

Whatnot·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Coding round at Whatnot for a software engineer role. One of the questions was a sorted squares variant, pretty close to a well-known leetcode problem.

Questions Asked (1)

Q1

Given a sorted array of integers, return a new array of the squares of each element, also in sorted order.

Algorithms & Data Structures
Author's notes

Classic two-pointer setup if you know it, but I went with sort-after-squaring first and they pushed me to optimize.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, then propose a two-pointer approach from both ends of the sorted array to build the result in descending order. Compare absolute values, square the larger one, and place it at the end of the result array, moving the corresponding pointer inward. This achieves O(n) time and O(n) space, which is optimal.

Pro tip: Mention that the two-pointer approach works because the largest square must come from either the most negative or most positive element, and building the result from the end avoids extra sorting. Also, note that you can do it in-place if allowed, but returning a new array is safer.

1. Clarify and confirm

Ask if the array can contain negative numbers, if it's sorted ascending, and if the output should be a new array. Confirm edge cases like empty array or single element.

2. Explain brute force and its complexity

Mention that squaring each element and sorting would be O(n log n), which is suboptimal. This shows you understand the baseline.

3. Propose two-pointer approach

Use two pointers at the start and end of the array. Compare absolute values, square the larger one, and place it at the end of the result array, moving the pointer inward.

4. Walk through an example

Demonstrate with a small array like [-4, -1, 0, 3, 10] to show how the pointers move and the result is built from the back.

5. Analyze complexity and edge cases

State O(n) time and O(n) space. Discuss handling empty array, all negatives, all positives, and duplicates.

Key Points to Mention

  • The array is sorted, so the largest squares are at the extremes (most negative or most positive).
  • Two-pointer technique from both ends to avoid sorting after squaring.
  • Building the result array from the end to maintain sorted order.
  • Time complexity O(n) and space complexity O(n) for the output array.
  • Edge cases: empty array, single element, all negative, all positive, zeros.
  • Comparison of absolute values to decide which pointer to move.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.