✅ C++ | Backtracking | Simple take / not-take | Detailed Explanation
Explanation\n\n\n\n\n\n\n\n\n\n\n\n\n# Complexity\n- Time complexity:O(2^n*n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your
# Explanation\n\n![image.png](https://assets.leetcode.com/users/images/d8a3f888-a0e2-4237-9bac-1c5963baea34_1692346908.308582.png)\n![image.png](https://assets.leetcode.com/users/images/f34bf987-3930-456f-a8dc-0fd5879796a7_1692346915.9082508.png)\n![image.png](https://assets.leetcode.com/users/images/ebc423b3-dc71-4ff6-bcec-9cd52f144e6f_1692346948.5512059.png)\n![image.png](https://assets.leetcode.com/users/images/551e21b0-a0c1-4e50-824a-cbc9293aefaf_1692346973.0115361.png)\n![image.png](https://assets.leetcode.com/users/images/78de58d7-c226-4d49-b2a4-454ec62a4757_1692346992.214744.png)\n![image.png](https://assets.leetcode.com/users/images/c8ab6c60-adf5-4a12-8c94-eca866ff9cdc_1692347899.7747571.png)\n![image.png](https://assets.leetcode.com/users/images/0f6be769-f24f-4b1f-897e-209f8c639ca6_1692347975.8818643.png)\n![image.png](https://assets.leetcode.com/users/images/491acd00-fb6a-4c7d-acac-0ad8894836d8_1692347986.9921937.png)\n![image.png](https://assets.leetcode.com/users/images/20c9564c-98f5-4dde-90ac-3b1a47e2d66f_1692348001.4688044.png)\n\n\n# Complexity\n- Time complexity:$$O(2^n*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 {\npublic:\n\n    bool canBeTaken(int i , int k , int taken , vector<int> &nums)\n    {\n        int curr = nums[i];\n        for(int i = 0 ; i < nums.size() ; i++)\n        {\n            if(taken & (1<<i))\n            {\n                if(nums[i] + k == curr || nums[i] - k == curr) return false;\n            }\n        }\n        return true;\n    }\n\n    int solve(int i, int k , vector<int> &nums , int &taken)\n    {\n        if(i == nums.size())\n        {\n            return taken > 0 ? 1 : 0;\n        }\n        int pick = 0;\n        if(canBeTaken(i,k,taken,nums))\n        {\n            taken |= (1<<i);\n            pick = solve(i+1,k,nums,taken);\n            taken ^= (1<<i);\n        } \n        int notPick = solve(i+1,k,nums,taken);\n        return pick + notPick;\n    }\n\n    int beautifulSubsets(vector<int>& nums, int k) {\n        int takenTrack = 0;\n        return solve(0,k,nums,takenTrack);\n    }\n};\n```
['Backtracking', 'Bit Manipulation', 'Bitmask', 'C++']