Simple c++ solution with explanation. (Easiest way to remove duplicates[not using sets])
To get all the subsets, for each element in the array, we have 2 choices \nEither include it in subset or not.\nJust need to improve on that approach to remove 
To get all the subsets, for each element in the array, we have 2 choices \nEither include it in subset or not.\nJust need to improve on that approach to **remove duplicates**, which can be done easily by just making sure that if the last element in our present subset is equal to our present element, then you have to surely include present element in the subset , i.e, dont skip the present element.\nThe subset which will form if we don\'t include the present element will lead to duplicacy.\nBasically :\n```\nif nums[posn] = subset.back() //  subset.back() = last element in our present subset\n\t\tnext recursion call after including nums[posn] in the subset\nelse \t\n\t\t1. recursion call without including present element\n\t\t2. recursion call after including present element\n\t\t\n```\n###  C++ code \n```\nclass Solution {\n    // Final 2d array/vector to hold the answer\n    vector<vector<int>> ans;\npublic:\n    void fun(vector<int> nums,int n,vector<int> v,int i=0)\n    {\n        // when posn reaches the end of the input array, insert the present vector in to ans.     \n        if(i==n){\n            ans.push_back(v);\n            return;\n        }\n        /* when present element is not equal to last element in vector,\n        then only skip the                  \n        present element */    \n        if(v.empty()||v.back()!=nums[i])\n        {\n            fun(nums,n,v,i+1);\n        }\n        /* add the present element to the present subset and call for the remaining array */\n        v.push_back(nums[i]);\n        fun(nums,n,v,i+1);\n    }\n    vector<vector<int>> subsetsWithDup(vector<int>& nums) {\n        vector<int> v;\n        // Sort the input array so that all duplicate elements are together.\n        sort(nums.begin(),nums.end());\n        \n        fun(nums,nums.size(),v);\n        \n        return ans;\n    }\n};\n```\nps:- try to make the recursion tree for an example test case ( [1,2,2] ) to understand it better.
['Recursion', 'C']