C++ | backtrack + binary search (to prevent tle)
\n# Code\n\nclass Solution {\npublic:\n    \n    int helper(vector<int>& nums, vector<int>& dp, int k, int i, int n) {\n        if (i == n) return 0;\n        \
\n# Code\n```\nclass Solution {\npublic:\n    \n    int helper(vector<int>& nums, vector<int>& dp, int k, int i, int n) {\n        if (i == n) return 0;\n        \n        int take = 0;\n        \n        int notTake = helper(nums,dp,k,i + 1,n);\n        \n        if (binary_search(dp.begin(), dp.end(), nums[i] - k) == 0)\n        {\n            dp.push_back(nums[i]);\n            take = 1 + helper(nums,dp,k,i + 1,n);\n            dp.pop_back();\n        }\n    \n        return take + notTake;\n    }\n    \n    int beautifulSubsets(vector<int>& nums, int k) {\n        int n = nums.size();\n        sort(nums.begin(),nums.end());\n        vector<int> dp;\n        \n        return helper(nums,dp,k,0,n);\n    }\n};\n```
['Binary Search', 'Dynamic Programming', 'Backtracking', 'C++']