Easy C++ Solution | Beats 100 💯✅
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem of finding beautiful subsets involves selecting subsets of an array such th
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem of finding beautiful subsets involves selecting subsets of an array such that for any two elements in the subset, their absolute difference is not equal to a given value \n\uD835\uDC58. The intuition behind our approach is based on recursive exploration of all possible subsets while ensuring that the condition on absolute difference is maintained.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe approach to solve the problem is structured as follows:\n\n1. Sorting: \n    1. Purpose: Sort the array to simplify the checking of the condition.\n    2. Impact: This allows us to efficiently check if adding an element would violate the condition, as elements are processed in ascending order.\n2. Use of HashMap:\n    1. Purpose: Keep track of the elements included in the current subset.\n    2. Impact: Enables efficient checking of the condition whether an element can be included in the current subset.\n3. Recursive Function:\n    1. Base Case: If we have processed all elements, increment the count of beautiful subsets.\n    2. Recursive Case: For each element, decide to include or exclude it in the current subset based on the condition.\n4. Backtracking:\n    1. Purpose: Ensure we explore all possible subsets without violating the condition.\n    2. Impact: Allows us to explore subsets by adding and removing elements dynamically and backtracking when necessary.\n# Complexity\n- Time complexity: O(nlogn+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    int ans;\n    unordered_map<int, int> rec;\n    int beautifulSubsets(vector<int>& nums, int k) {\n        sort(nums.begin(), nums.end());\n        ans = 0;\n        vector<int> tmp;\n        int n = nums.size();\n        for (int i = 0; i < n; ++i) {\n            rec[nums[i]]++;\n            recursion(i+1, n, tmp, nums, k);\n            rec[nums[i]]--;\n        }\n        return ans;\n    }\n    void recursion(int pos, int n, vector<int> &tmp, vector<int>& nums, int k) {\n        if (pos == n) {\n            ans++;\n            return;\n        }\n        if (rec[nums[pos] - k] == 0) {\n            rec[nums[pos]]++;\n            recursion(pos + 1, n, tmp, nums, k);\n            rec[nums[pos]]--;\n        }   \n        recursion(pos + 1, n, tmp, nums, k);   \n    }\n};\n```
['Array', 'Backtracking', 'Recursion', 'Ordered Map', 'Sorting', 'C++']