C++ Easiest Solution | Easy |
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:$$O(2^n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    void dfs(vector<int> &nums, int idx, int k, unordered_map<int, int> &mp, int &ans) {\n        if(idx == nums.size()) ans++;\n        else {\n            if(!mp[nums[idx] - k] && !mp[nums[idx] + k]) {\n                mp[nums[idx]]++;\n                dfs(nums, idx + 1, k, mp, ans);\n                mp[nums[idx]]--;\n            }\n            dfs(nums, idx + 1, k, mp, ans);\n        }\n    }\n\n    int beautifulSubsets(vector<int>& nums, int k) {\n        int ans = 0;\n        unordered_map<int, int> mp;\n        dfs(nums, 0, k, mp, ans);\n        return ans - 1;\n    }\n};\n```
['Backtracking', 'Depth-First Search', 'Ordered Map', 'C++']