Java | Backtracking | 10 lines | Clean code
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# 
# 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 {\n  private int dfs(int[] nums, int k, int i, Set<Integer> set) {\n    if (i == nums.length)\n     return set.isEmpty() ? 0 : 1;\n\n    var cnt = dfs(nums, k, i+1, set);\n    \n    if (set.contains(nums[i] - k)) return cnt;\n\n    set.add(nums[i]);\n    cnt += dfs(nums, k, i+1 ,set);\n    set.remove(nums[i]);\n\n    return cnt;\n  }\n\n  public int beautifulSubsets(int[] nums, int k) {\n    Arrays.sort(nums);\n\n    return dfs(nums, k, 0, new HashSet<Integer>());\n  }\n}\n```\nIf you like my solution, please upvote it!
['Array', 'Backtracking', 'Sorting', 'Java']