C++| Backtracking | Faster than 100% C++ submissions
Approach used- Backtracking\n\nclass Solution {\npublic:\n    vector<vector<int>> subsetsWithDup(vector<int>& nums) {\n        vector<vector<int>> ans;       //
Approach used- Backtracking\n```\nclass Solution {\npublic:\n    vector<vector<int>> subsetsWithDup(vector<int>& nums) {\n        vector<vector<int>> ans;       //to store all susbets\n        vector<int> curr;         //to store current individual subset (that we will build)\n        sort(nums.begin(),nums.end());      //sort the array so that duplicates are adjacent \n        helper(nums,ans,curr,0);       //we start from index 0\n        return ans;\n        \n    }\n    \n    void helper(vector<int>& nums, vector<vector<int>>& ans, vector<int>& curr, int idx){\n        ans.push_back(curr);       //we include current susbet into final ans\n        for(int i=idx;i<nums.size();i++){     //check for all possibilites\n            if(i>idx &&  nums[i]==nums[i-1]) continue;      //if duplicate then we continue\n            curr.push_back(nums[i]);     //we include nums[i] in current subset\n            helper(nums,ans,curr,i+1); \n            curr.pop_back();         //to get subset without nums[i]\n        }\n    }  \n};\n```\nHope you found this useful :)\n
['Backtracking', 'Recursion', 'C', 'Sorting', 'C++']