Subset generation | video solution | easy
\n\n# Approach\nA basic subset generation question, The idea is to add elements which satisfy the constraints i.e. abs(nums[idx]-any_element_in_subset)!=k.\nIn 
\n\n# Approach\nA basic subset generation question, The idea is to add elements which satisfy the constraints i.e. abs(nums[idx]-any_element_in_subset)!=k.\nIn each recursive call add the current element to the subset &update the mask (if the above condition holds). Irrespective of the condition holding true. You can avoid the current element and jump to the next one without modifying the mask. \nTo remove the nonempty subset from the calculation subtract 1 at the end.\n The code is self-explanatory and have provided a link to the video which goes over the code too:  https://www.youtube.com/watch?v=scYIG0OHEEg\n# Code\n```\nclass Solution {\npublic:\n    int res=0;\n    void cal(int idx,vector<int>& nums,int k,int mask){\n        bool cant=false;\n        if(idx==nums.size())    {res++;return;}\n        for(int i=0;i<idx;i++){\n            if(mask&(1<<i)){            // is set .... \n                if(abs(nums[i]-nums[idx])==k){\n                    cant=true;\n                    break;\n                }\n            }\n        }\n        if(!cant)   cal(idx+1,nums,k,mask|(1<<idx));        // add \n        cal(idx+1,nums,k,mask);                             // don\'t\n    }\n    int beautifulSubsets(vector<int>& nums, int k) {\n        res=0;\n        cal(0,nums,k,0);\n        return res-1;\n        \n    }\n};\n```
['C++']