The Find Original Array From Doubled Array interview question is a reconstruction challenge. You are given a "changed" array that was supposedly formed by taking an original array and appending twice the value of every element to it. For example, if the original was [1, 3, 4], the changed array could be [1, 3, 4, 2, 6, 8]. Your task is to find the original array or return an empty array if the input is not a valid doubled array.
Companies like Google and Microsoft ask the Find Original Array coding problem to test your proficiency with Hash Tables and Sorting. It evaluations if you can identify a clear starting point (the smallest element) and greedily match it with its double. It’s a test of logical consistency and frequency management.
This problem follows the Greedy and Frequency Counting patterns.
[].count[x] is :
count[x] occurrences of to pair them up.count[2x] < count[x], reconstruction is impossible. Return [].count[x] times and subtract that from count[2x].Array: [1, 3, 4, 2, 6, 8]
[1, 2, 3, 4, 6, 8]. Frequencies: {1:1, 2:1, 3:1, 4:1, 6:1, 8:1}.count[2] becomes 0.count[6] becomes 0.count[8] becomes 0.
Result: [1, 3, 4].Whenever you need to "pair" elements based on a numeric relationship, Sorting is usually your first step. It provides a deterministic order that allows for a greedy matching strategy. This is a vital Hash Table interview pattern.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Hand of Straights | Medium | Solve | |
| Divide Array in Sets of K Consecutive Numbers | Medium | Solve | |
| Array of Doubled Pairs | Medium | Solve | |
| Largest Values From Labels | Medium | Solve | |
| Least Number of Unique Integers after K Removals | Medium | Solve |