C++, AC, Regular backtracking solution for both subsets I and II
void dfs(vector<int> &S, int start, vector<int> &output, vector<vector<int>> &result) {\n        result.push_back(output);\n        \n        for (int i = start
    void dfs(vector<int> &S, int start, vector<int> &output, vector<vector<int>> &result) {\n        result.push_back(output);\n        \n        for (int i = start; i < S.size(); i++) {\n            output.push_back(S[i]);\n            dfs(S, i + 1, output, result);\n            output.pop_back();\n            // disable following line for subset I\n            while (i + 1 < S.size() && S[i + 1] == S[i]) i++;\n        }\n    }\n    \n    vector<vector<int> > subsetsWithDup(vector<int> &S) {\n        vector<vector<int>> result;\n        vector<int> output;\n        \n        if (0 == S.size()) {\n            result.push_back(output);\n            return result;\n        }\n        \n        sort(S.begin(), S.end());\n        dfs(S, 0, output, result);\n        return result;\n    }
[]