← Questions

Recover the original array from its doubled shuffle

0
GoogleCodingLast asked Jan 2026

A coding interview question asked in Google's first round (coding), last asked Jan 2026. It tests hash maps, sorting and greedy.

An array original was turned into changed by appending, for every element x, the value 2 * x, and then shuffling the result. Given changed, return original, or an empty list if changed could not have been made this way.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • find_original(changed: list[int]) -> list[int] — any order is accepted; sorted here for readability.

Example

[1, 3, 4, 2, 6, 8]   ->  [1, 3, 4]
[6, 3, 0, 1]         ->  []          # 1 needs a 2
[0, 0, 0, 0]         ->  [0, 0]      # zero pairs with zero
[-2, -4, 1, 2]       ->  [-2, 1]
[1]                  ->  []          # odd length

Constraints

  • 1 <= len(changed) <= 10^5.
  • Values can be negative or zero.

Clarifying questions

  • Can values be negative or zero?
  • Does the order of the returned array matter?
  • If several originals are possible, is any one fine?

What a strong answer covers

  • Odd length means no answer.
  • A count map, then process values in increasing absolute value: the smallest remaining value by magnitude cannot be the double of anything left, so it must be an original and must pair with its double.
  • Zeros: they pair with each other, so their count must be even.
  • Why sorting by plain value fails for negatives (for -4 and -2, -2 is the original).
  • O(n log n) for the sort, or O(n + range) with counting; tests for zeros, negatives and repeats.

Follow-ups

  • The multiplier is k instead of 2.
  • Return every possible original array.
  • changed arrives as a stream: when can you emit an original value?

Where it's asked

  • Google · First round: coding · Last asked Jan 202645 min · Coding in a Google Doc, no syntax highlighting or autocomplete · No AI

What it tests

hash maps · sorting · greedy

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding