⭐⭐Easy C++ solution with loop and backtracking||O(N)🚀🔥||unique???
INTUITION \nAs we have solved the question of finding subsets, here we will use similar approach to find the subsets for this question. make an array of all sub
# INTUITION \nAs we have solved the question of finding subsets, here we will use similar approach to find the subsets for this question. make an array of all subsets and then **remove duplicates using inbuilt functions**\n# APPROACH\n1.  We are using here recursive technique. so firstly declare two vector ... one for answer and other as auxillary one.\n2.  make a recursive function **solve** which will give all subsets recursively \n3. **parameters for solve function** - answer vector, output vector, input vector and index for traversing.\n4. HERE, we will play exclude and include game, in excluding step, just increase the index by 1.\n5. for include, first we extract the elements from input vector and insert in the output vector ......and then make a recursive call.\n6. when the **base case(index>= nums.size())** is reached, insert the output vector in answer vector and return.\n\n# COMPLEXITY\n**TIME COMPLEXITY**-  overall is O(N)\n**SPACE COMPLEXITY**- O(N)\n```\nclass Solution {\npublic:\n    void solve(vector <int> nums, vector<int> temp, int index, vector<vector<int>>& ans)\n    {\n        if(index >= nums.size())\n        {\n            ans.push_back(temp);\n            return ;\n        }\n        \n        solve(nums, temp, index+1, ans);\n        \n        int key = nums[index];\n        temp.push_back(key);\n        solve( nums, temp, index+1, ans);\n    }\n    vector<vector<int>> subsetsWithDup(vector<int>& nums) {\n        sort(nums.begin(), nums.end());\n        vector<vector<int>> ans;\n        vector <int> temp;\n        solve(nums, temp, 0, ans);\n        sort(ans.begin(), ans.end());\n        \n        ans.erase(unique(ans.begin(), ans.end()), ans.end());\n        \n        return ans;\n        \n    }\n};\n```\n\n\n\n\n
['C++']