Find the Original Array From a Doubled Array
Updated
Problem statement
An unknown array original contains non-negative integers. A changed array was formed by appending twice every value in original, then shuffling all values.
Given changed, reconstruct original and return it sorted from smallest to largest. Return an empty array when no valid original array exists.
Each occurrence is a separate element. In particular, every original zero requires a second zero as its doubled partner.
Function
findOriginalArray(changed: int[]) → int[]Examples
Example 1
changed = [1,3,4,2,6,8]return = [1,3,4]Values 1, 3, and 4 pair with 2, 6, and 8.
Example 2
changed = [6,3,0,1]return = []No ordering can pair every value with its double.
Example 3
changed = [0,0,2,4]return = [0,2]One zero pairs with the other zero, and 2 pairs with 4.
Constraints
0 <= changed.length <= 200000.changed.lengthis even.0 <= changed[i] <= 1000000000.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Minimum Distinct Prefix CostChubb · OAChubb interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Rearrange Songs by AuthorZomato / Eternal · OAZomato / Eternal interview questions
- Nickname-Constrained GroupingZoox · ONSITE INTERVIEW
- Partition Into K-Size Consecutive GroupsDream11 · ONSITE INTERVIEWDream11 interview questions
- Find Max Health SumAmazon · OA
- Fair Capped Money DistributionGusto · PHONE SCREEN · ONSITE INTERVIEWGusto interview questions
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions