Simple Java Solution based on backtracking with Comments - 1ms
Approach:\nThis is a classic backtracking problem is solved using the recommened template of\n- make a choice\n- backtrack\n- undo your choice\n\nCaveats:\nThe 
**Approach:**\nThis is a classic backtracking problem is solved using the recommened template of\n- make a choice\n- backtrack\n- undo your choice\n\n**Caveats:**\nThe choice to sort the array introduces `O(n log n)` complexity but the worst-case complexity for generating the subsets is already `O(2^n)`.\nThis allows us to use sorting without any impact on overall time complexity of the solution.\n\n```\nclass Solution {\n    public List<List<Integer>> subsetsWithDup(int[] nums) {\n        // sorting our array will allow us to skip repetitions easily\n        Arrays.sort(nums);\n        List<List<Integer>> res = new ArrayList<>();\n        backtrack(nums, 0, new ArrayList<>(), res);\n        return res;\n    }\n    \n    private void backtrack(int[] a, int idx, List<Integer> curr, List<List<Integer>> res) {\n        // Be careful to always add a copy of the list;\n\t\t// else you would essentially be changing the same list over and over again\n\t\tres.add(List.copyOf(curr));\n        if(idx == a.length) return;\n        \n        for(int i=idx; i<a.length; i++) {\n            curr.add(a[i]); // make a choice (add the number at index)\n            backtrack(a, i+1, curr,res); // backtrack (generate dependent subsets)\n            curr.remove(curr.size()-1); // undo your choice (remove the number)\n            \n            // This is the tricky part; we want to skip all the repetitions of the number\n            while(i+1 < a.length && a[i] == a[i+1]) {\n                i += 1;\n            }\n        }\n    }\n}\n```\n\n**Please Vote up, if this helped you!!**\n\nHappy Coding!! :)
['Backtracking', 'Java']