<p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p>

<p>Given an array <code>changed</code>, return <code>original</code><em> if </em><code>changed</code><em> is a <strong>doubled</strong> array. If </em><code>changed</code><em> is not a <strong>doubled</strong> array, return an empty array. The elements in</em> <code>original</code> <em>may be returned in <strong>any</strong> order</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> 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].
</pre>

<p><strong class="example">Example 2:</strong></p>

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

<p><strong class="example">Example 3:</strong></p>

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

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= changed.length &lt;= 10<sup>5</sup></code></li>
	<li><code>0 &lt;= changed[i] &lt;= 10<sup>5</sup></code></li>
</ul>

class Solution:
    def dfs(self, changed_dict, original_dict, st_idx=0):
        for i, c in enumerate(self.changed[st_idx:]):
            if changed_dict[c] == 0:
                continue
            changed_dict[c] -= 1
            is_doubled, is_original = False, False
            # check if is_original
            c_doubled = c * 2
            if c_doubled in changed_dict and changed_dict[c_doubled] > 0:
                is_original = True
                if c in original_dict:
                    original_dict[c] += 1
                else:
                    original_dict[c] = 1
                changed_dict[c_doubled] -= 1
                is_original = self.dfs(changed_dict, original_dict, st_idx+i)
                if is_original:
                    return True
                changed_dict[c_doubled] += 1
            # check if is_doubled
            if c % 2 == 0:
                c_half = c // 2
                if c_half in changed_dict and changed_dict[c_half] > 0:
                    is_doubled = True
                    if c_half in original_dict:
                        original_dict[c_half] += 1
                    else:
                        original_dict[c_half] = 1
                    changed_dict[c_half] -= 1
                    is_doubled = self.dfs(changed_dict, original_dict, st_idx+1)
                    if is_doubled:
                        return True
                    changed_dict[c_half] += 1
            if not is_original and not is_doubled:
                changed_dict[c] += 1
                return False
        return True

    def findOriginalArray(self, changed: List[int]) -> List[int]:
        c = collections.Counter(changed)
        if c[0] % 2:
            return []
        for x in sorted(c):
            if c[x] > c[2 * x]:
                return []
            c[2 * x] -= c[x] if x else c[x] // 2
        return [int(f) for f in c.elements()]
710