<p>Given a collection of numbers, <code>nums</code>,&nbsp;that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>

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

<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
 [1,2,1],
 [2,1,1]]
</pre>

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

<pre>
<strong>Input:</strong> nums = [1,2,3]
<strong>Output:</strong> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
</pre>

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

<ul>
	<li><code>1 &lt;= nums.length &lt;= 8</code></li>
	<li><code>-10 &lt;= nums[i] &lt;= 10</code></li>
</ul>

#include<vector>
#include<unordered_map>
class Solution {
    
private:
    std::vector<std::vector<int>> results{};
    
    std::unordered_map<int, int> popFreqMap(vector<int>&  nums) {
        std::unordered_map<int,int> freq_map{};
        for(auto num : nums) {
            freq_map[num]++;
        }
        return freq_map;
    }

    void createCombo(std::unordered_map<int,int> freq_map, vector<int> combo, size_t size)
    {
        if(combo.size() == size) {
            results.push_back(combo);
        } else {
            for(auto [key, value] : freq_map) {
                if(value) {
                    auto new_map = freq_map;
                    auto temp_combo = combo;
                    temp_combo.push_back(key);
                    new_map.at(key)--;
                    createCombo(new_map, temp_combo, size);
                }
                
            }
        }
    }

public:
    vector<vector<int>> permuteUnique(vector<int>& nums) {
        auto freq_map = popFreqMap(nums);
        createCombo(freq_map, {}, nums.size());
        return results;
    }
};
24108