# 2007. Find Original Array From Doubled Array

#### Medium

***

An integer array `original` is transformed into a **doubled** array `changed` by appending **twice the value** of every element in `original`, and then randomly **shuffling** the resulting array.

Given an array `changed`, return `original` *if* `changed` *is a **doubled** array. If* `changed` *is not a **doubled** array, return an empty array. The elements in* `original` *may be returned in **any** order*.

&#x20;

**Example 1:**

<pre><code>Input: changed = [1,3,4,2,6,8]
<strong>Output:
</strong> [1,3,4]
<strong>Explanation:
</strong> One possible original array could be [1,3,4]:
- Twice the value of 1 is 1 * 2 = 2.
- Twice the value of 3 is 3 * 2 = 6.
- Twice the value of 4 is 4 * 2 = 8.
Other original arrays could be [4,3,1] or [3,1,4].
</code></pre>

**Example 2:**

<pre><code>Input: changed = [6,3,0,1]
<strong>Output:
</strong> []
<strong>Explanation:
</strong> changed is not a doubled array.
</code></pre>

**Example 3:**

<pre><code>Input: changed = [1]
<strong>Output:
</strong> []
<strong>Explanation:
</strong> changed is not a doubled array.
</code></pre>

&#x20;

**Constraints:**

* `1 <= changed.length <= 105`
* `0 <= changed[i] <= 105`

```python
class Solution:
    def findOriginalArray(self, changed: List[int]) -> List[int]:
        counter = collections.Counter(changed)
        # Odd Zeroes
        if counter[0] % 2:
            return []
        for ele in sorted(counter):
            if counter[ele] > counter[ele*2]:
                return []
            counter[ele*2] -= counter[ele] if ele else counter[ele]//2
        return list(counter.elements())
                
```
