⌛SAME CODE WITH TWEAKING SOLVED 2 PROBLEMS || EASY TO UNDERSTAND
CHECK THE RECURSION TREE BELOW FOR BETTER UNDERSTANDING .\n\nSIMILAR QUESTION LINK WITH SOLUTION \nhttps://leetcode.com/problems/non-decreasing-subsequences/des
# CHECK THE RECURSION TREE BELOW FOR BETTER UNDERSTANDING .\n\n**SIMILAR QUESTION LINK WITH SOLUTION **\nhttps://leetcode.com/problems/non-decreasing-subsequences/description/\n\nhttps://leetcode.com/problems/non-decreasing-subsequences/solutions/3085690/same-code-with-tweaking-solved-2-problems-easy-to-understand/\n\n# Intuition\nSame code is used in solving Non decreasing Subsequence question .\n\n# Approach\nWe are sorting given array. And find all subsequence it can can make ,along with the check that subset should not be repeated .\ni.e.\n if(ds.size()==0 || arr[ind]!=ds[ds.size()-1])\n\n# Code\n```\n\nclass Solution {\npublic:\n    vector<vector<int>>ans;\n    void subsequence(int ind,int n,vector<int>&arr,vector<int>&ds){\n    if(ind==n){\n        ans.push_back(ds);\n        return;\n    }\n // Since in this question we can change the order of the array elements unlike question(https://leetcode.com/problems/non-decreasing-subsequences/description/).\n    //  Therefore we sorted the nums vector initially.\n    //  Therefore condition , if(ds.size()==0 || nums[index] >= ds[ds.size()-1]) is not required .\n    ds.push_back(arr[ind]);\n    subsequence(ind+1,n,arr,ds);\n    ds.pop_back();\n    if(ds.size()==0 || arr[ind]!=ds[ds.size()-1])subsequence(ind+1,n,arr,ds);\n}\n    vector<vector<int>> subsetsWithDup(vector<int>& nums) {\n        sort(nums.begin(),nums.end());\n        vector<int>ds;\n        subsequence(0,nums.size(),nums,ds);\n        return ans;\n    }\n};\n```\n\n## ![image.png](https://assets.leetcode.com/users/images/b241b88c-e53b-42d2-9fb5-4e111c7e7d27_1674383113.75447.png)\n\n\n#UPVOTE IF YOU LIKED THE EFFORT\nTHANK YOU\nCODE BY :) AMAN MAURYA\n
['C++']