✅ Easy C++ Solution
Code\n\nvoid backtrack(const vector<int>& nums, int k, unordered_map<int, int>& flag, int pos, int& res)\n{\n    if(pos == nums.size())\n    {\n        res++;\n
# Code\n```\nvoid backtrack(const vector<int>& nums, int k, unordered_map<int, int>& flag, int pos, int& res)\n{\n    if(pos == nums.size())\n    {\n        res++;\n        return;\n    }\n    backtrack(nums, k, flag, pos + 1, res);\n    int num = nums[pos];\n    if(!flag[num - k])\n    {\n        flag[num]++;\n        backtrack(nums, k, flag, pos + 1, res);\n        flag[num]--;\n    }\n}\n\nclass Solution {\npublic:\n    int beautifulSubsets(vector<int>& nums, int k) {\n        sort(nums.begin(), nums.end());\n        unordered_map<int, int> flag;\n        int res = 0;\n        backtrack(nums, k, flag, 0, res);\n        return res - 1;\n    }\n};\n```
['C++']