Standard Backtracking
\n# Solution 1\n\nclass Solution {\npublic:\n    int beautifulSubsets(vector<int>& nums, int k) {\n        vector<int> cur;\n        return helper(nums, k, cur,
\n# Solution 1\n```\nclass Solution {\npublic:\n    int beautifulSubsets(vector<int>& nums, int k) {\n        vector<int> cur;\n        return helper(nums, k, cur, 0);\n    }\n    private:\n    int helper(vector<int>& nums, int k, vector<int>& cur, int start) {\n        int cnt = 0;\n        for (int i = start; i < nums.size(); ++i) {\n            if (!test(cur, nums[i], k))\n                continue;\n            cur.push_back(nums[i]);\n            cnt++;\n            cnt += helper(nums, k, cur, i + 1);\n            cur.pop_back();\n        }\n        return cnt;\n    }\n    bool test(vector<int>& cur, int num, int k) {\n        for (auto &c : cur)\n            if (abs(num - c) == k)\n                return false;\n        return true;\n    }\n};\n```\n\n# Solution2 : HashMap cur frequency\n```\nclass Solution {\npublic:\n    int beautifulSubsets(vector<int>& nums, int k) {\n        unordered_map<int, int> cur;\n        return helper(nums, k, cur, 0);\n    }\nprivate:\n    int helper(vector<int>& nums, int k, unordered_map<int, int>& cur, int start) {\n        int cnt = 0;\n        for (int i = start; i < nums.size(); ++i) {\n            if (cur[nums[i] - k] || cur[nums[i] + k])\n                continue;\n            cur[nums[i]]++;\n            cnt += 1 + helper(nums, k, cur, i + 1);\n            cur[nums[i]]--;\n        }\n        return cnt;\n    }\n};\n```
['C++']