python backtracking
Code\n\nclass Solution:\n    def beautifulSubsets(self, nums: List[int], k: int) -> int:\n        n = len(nums)\n        output = 0\n        \n        def dfs(i
# Code\n```\nclass Solution:\n    def beautifulSubsets(self, nums: List[int], k: int) -> int:\n        n = len(nums)\n        output = 0\n        \n        def dfs(i, ctr):\n            nonlocal output\n            if i == n:\n                if ctr:\n                    output += 1\n                return\n            \n            if nums[i] - k not in ctr and nums[i] + k not in ctr:\n                ctr[nums[i]] += 1\n                dfs(i + 1, ctr)\n                ctr[nums[i]] -= 1\n                if not ctr[nums[i]]:\n                    del ctr[nums[i]]\n            dfs(i + 1, ctr)\n        \n        dfs(0, Counter())\n        return output\n            \n```
['Python3']