solution using JavaScript that beats 89%+ of users.
\n\n\n# Intuition\nTo solve this problem, we need to count all non-empty subsets of the given array nums where no two elements in any subset have an absolute di
![image.png](https://assets.leetcode.com/users/images/e13e93ce-1f5c-4b32-a784-0cff88680c7b_1716478445.6708097.png)\n\n\n# Intuition\nTo solve this problem, we need to count all non-empty subsets of the given array `nums` where no two elements in any subset have an absolute difference equal to `k`. This involves generating all possible subsets and checking the condition for each subset.\n\n# Approach\n1. Use a recursive function to generate all possible subsets of the given array.\n2. For each element in the array, create a new subset excluding elements that have an absolute difference of `k` with the current element.\n3. Recursively count the beautiful subsets for the newly formed subset.\n4. Keep track of the total count of beautiful subsets.\n\n# Complexity\n- Time complexity: $$O(2^n)$$ because we are generating all possible subsets of the array.\n\n- Space complexity: $$O(2^n)$$ due to the recursion stack and storage of subsets.\n\n# Code\n```javascript\n/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nconst beautifulSubsets = (nums, k) => {\n    const countBeautifulSubsets = (subset) => {\n        const len = subset.length;\n        if (len === 0) return 0;\n        \n        let totalBeautifulSubsets = 0;\n        \n        for (let i = 0; i < len; i++) {\n            const newSubset = [];\n            for (let j = i + 1; j < len; j++) {\n                if (Math.abs(subset[i] - subset[j]) !== k) {\n                    newSubset.push(subset[j]);\n                }\n            }\n            totalBeautifulSubsets += 1 + countBeautifulSubsets(newSubset);\n        }\n        \n        return totalBeautifulSubsets;\n    };\n\n    return countBeautifulSubsets(nums);\n};\n\n// Example\nconsole.log(beautifulSubsets([2, 4, 6], 2)); // Output: 4\n\n```
['JavaScript']