Clean Codes🔥🔥|| Full Explanation✅|| BackTracking✅|| Java
What Problem says ?\n- You are given an array nums of positive integers and  positive integer k.\n- A subset of nums is beautiful if it does not contain two int
# What Problem says ?\n- You are given an array `nums` of positive integers and  positive integer `k`.\n- A subset of `nums` is beautiful if it does not contain two integers with an absolute difference equal to `k`.\n- Return the number of non-empty beautiful subsets of the array ```\nnums\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach : BackTracking\n- Here we are using a backtracking algorithm to generate all possible subsets of the array and checks if each subset is beautiful. \n- To do this, we start by sorting the array in ascending order. Then use a recursive function called `backTrack` to generate all possible subsets of the array.\n- The `backTrack` function takes a `set` of integers, element, an index `i`, the array `nums`, and `k` as input. \n- It adds the current element at index `i` to the element `set` and recursively calls itself with `i+1` as the new index. \n- If the new subset is beautiful, the `count` variable is incremented.\n-  Finally, the current element is removed from the element set to backtrack and generate the next subset.\n- The function `beautifulSubsets` simply calls backTrack function with an empty element set and returns the count variable minus one, since the empty subset is not considered beautiful.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity :\n- Time complexity : O(n log n + 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# Please Upvote\uD83D\uDC4D\uD83D\uDC4D\n```\nThanks for visiting my solution.\uD83D\uDE0A\n```\n# Java Code :\n```\nclass Solution \n{\n    int count = 0;\n    public int beautifulSubsets(int[] nums, int k) \n    {\n        Arrays.sort(nums);\n        backTrack(new HashSet<>(), 0, nums, k);\n        return count - 1;\n    }\n    private void backTrack(Set<Integer> element ,int i, int[] nums, int k)\n    {\n        count++;\n        for(int j=i; j<nums.length; j++)\n        {\n            if( !element.contains(nums[j] - k ))\n            {\n                element.add(nums[j]);\n                backTrack(element, j+1, nums, k);\n                element.remove(nums[j]);//remove current elem before backtracking\n            }\n        }\n\n    }\n}\n```\n# Please Upvote\uD83D\uDC4D\uD83D\uDC4D\n![ezgif-3-22a360561c.gif](https://assets.leetcode.com/users/images/0f6145e7-82f4-493f-b830-7c317c2d32b0_1679223432.891085.gif)\n\n
['Array', 'Backtracking', 'Ordered Set', 'Java']