Simple Pick and Unpick Approach | C++ | Recursive Solution
Intuition\n Describe your first thoughts on how to solve this problem. \nWe can maintain a data structure which will tell us whether this particular element can
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can maintain a data structure which will tell us whether this particular element can be taken or not!\nIf we can take this we\'ll update the data structure and move forward\n\n---\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nCreate a map to keep count of the elements which you have taken\n\n- Unpick Case:\nNo condition Just increase the index in the next call\n\n- Pick Case:\n1. We can only pick if this elements (say x) , x-k and x+k should not be present in the map\n2. If this is the case put x in the map and move forward \n3. Upon returning we can backtrack this pick case\n\n---\n\n\n# Complexity\n- Time complexity : O(2^n)\n\n- Space complexity: O(2^n)\n\n# Code\n```\nclass Solution {\npublic:\n    unordered_map<int , int> count;\n    int solve(vector<int> & nums , int index  , int k){\n        if(index>=nums.size()){\n            return 1;\n        }\n\n        //unpick\n        int unpick = solve(nums , index+1 , k);\n\n        //pick\n        int pick = 0;\n        if(count[nums[index]-k]==0 && count[nums[index]+k]==0 ){\n            count[nums[index]]++;\n            pick = solve(nums , index+1 , k);\n            count[nums[index]]--;\n        } \n\n        return pick + unpick;\n    }\n    int beautifulSubsets(vector<int>& nums, int k) {\n        //empty hata diya!\n        return solve(nums, 0 , k)-1;\n    }\n};\n```
['Hash Table', 'Backtracking', 'Recursion', 'C++']