Grokking Microsoft Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
Find Original Array From Doubled Array (medium)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

A doubled array changed is formed from the original array after appending twice the value of each element in the original array and randomly shuffling elements in the updated original array.

Given an array changed, return the original array if changed is a valid doubled array. Otherwise, return empty array.

Examples

  • Example 1:

    • Input: changed = [2,4,1,8]
    • Expected Output: [1,4]
    • Justification: The original array [1,4] is doubled to form [2,4,1,8] (1's double is 2, and 4's double is 8).
  • Example 2:

    • Input: changed = [6,3,0,0]
    • Expected Output: [0,3]
    • Justification: The original array [0,3] is doubled to form [6,3,0,0] (0's double is 0, and 3's double is 6).
  • Example 3:

    • Input: changed = [1, 2, 2, 4, 4, 8, 16, 32]
    • Expected Output: [1, 2, 4, 16]
    • Justification: The original array [1, 2, 4, 16] is doubled to form [1, 2, 2, 4, 4, 8, 16, 32] (1's double is 2, 2's double is 4, 4's double is 8, and 16's double is 32).

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible