Ruby solution beats 100% both run time and memory.
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```\n# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef helper(nums, i, n, disabled, graph, selected)\n    if i == n\n        # base case\n        return selected > 0 ? 1 : 0\n    end\n\n    case1 = helper(nums, i+1, n, disabled, graph, selected)\n    if disabled & (1 << i) != 0\n        return case1  # can\'t select this\n    end\n\n    disabled |= graph[i]\n    case2 = helper(nums, i+1, n, disabled, graph, selected | (1 << i))\n\n    return case1 + case2\nend\n\ndef beautiful_subsets(nums, k)\n    n = nums.length\n    graph = [0] * n\n\n    (0...n).each do |i|\n        curr = nums[i]\n        (0...n).each do |j|\n            if nums[j] == curr + k || nums[j] == curr - k\n                graph[i] |= 1 << j\n            end\n        end\n    end\n\n    disabled = 0\n    return helper(nums, 0, n, disabled, graph, 0)\nend\n```
['Array', 'Dynamic Programming', 'Backtracking', 'Sorting', 'Ruby']