Java solution and explanation with Time and Space complexity
\n```\nclass Solution {\n    public List> subsetsWithDup(int[] nums) {\n        \n        //make sure to sort the array in ascending order so that we can detect
\n```\nclass Solution {\n    public List<List<Integer>> subsetsWithDup(int[] nums) {\n        \n        //make sure to sort the array in ascending order so that we can detect the dupicates side by side\n        Arrays.sort(nums);\n        \n        //create a list of list of integer anslist to return in the end\n        //this is the array list that will contain all the unique subsets lists\n        ArrayList<List<Integer>> ansList = new ArrayList<>();\n        \n        //Now lets call the recursion\n        findUniqueSubSets(0, nums, new ArrayList<Integer>(), ansList);\n        //the ArrayList<Integer>() is here because we need to return List<List<Integer>> here so \n        //our main arrayList is ansList which we\'ve already defined\n        //this ArrayList<Integer>() we\'ve defined so that we can store our individual lists here\n        //and we\'ll add this list to main list i.e ansList\n        \n        return ansList;\n    }\n    \n    public void findUniqueSubSets(int ind, int[] nums, ArrayList<Integer> ds, ArrayList<List<Integer>> ansList)\n    {\n        //initially we add an empty list to our ansList \n        //to generate an empty list like this -> [] \n        ansList.add(new ArrayList<Integer>(ds));\n        \n        //start chking from 0th to n-1th index. using for loop\n        for(int i = ind; i< nums.length; i++)\n        {\n            //chk for duplicates if any just avoid them\n            if( i != ind && nums[i] == nums[i-1]) continue;\n            //i != ind . ind is the first index always for which we are chking \n            //so if i is not ind then we are not visiting that element \n            //for the first time and might be and that might be a duplicate \n            //which we again chk using nums[i] == nums[i-1]\n            \n            //if we came across this if condition that only means that we are at an element \n            //which is not a duplicate \n            //so we have to add it to our arryalist ds\n            ds.add(nums[i]);\n            \n            //again call recursion for the next index\n            findUniqueSubSets(i+1, nums, ds, ansList);\n            \n            //while returning make sure to remove the element we added because \n            //we wouldn\'t want that to be present for the next recursion call\n            ds.remove(ds.size() -1);\n                \n        }\n    }\n    \n    }\n    \nTime Complexity: O(k * 2^n) -> O(2^n) for generating every subset + O(k) to insert every subset in another data structure. assuming average length of each subset is near about K.\n\nSpace Complexity: O(2^n * k) to store every subset and the Auxiliary space is O(n) if n is the depth of the recursion tree.\n\nI hope you find this helpful. Please do upvote in case you understood.\nThankss!
['Recursion', 'Java']