Bit Manipulation, quite intuitive :)
Intuition\n Describe your first thoughts on how to solve this problem. \nsince n=20, checking if a subset follows the condition, seemed possible for all subset.
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nsince n=20, checking if a subset follows the condition, seemed possible for all subset.it is easy to visualise all subsets with the help of set and unset bits as take and not take.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nfirstly i have collected all the pairs that must not be in my subset, that are the ones with difference =k.\nive again represented the pairs as set bits.\nFor eg, 2,4,6 here (2,4,_) and (_,4,6) these are the pairs with diff=k. ive represented as (110) and (011) respectively.\nthen, ive simply gone through each subset and discarded those subsets that have set bits as same as this (110), meaning 2,4 was taken in the subset . similarly for (011).\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nn^2 for going through all pairs, 2^n for (2^n)-1 subsets.\nO((2^n)*(n^2))\n- Space complexity:O(n^2)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int beautifulSubsets(vector<int>& v, int k) {\n        int n=v.size(),ans=0;\n        vector<int>p;// pairs with diff =k\n        for(int i=0; i<n; i++){\n            for(int j=i+1; j<n;j++){\n                if(abs(v[i]-v[j])==k){\n                    p.push_back((1<<(n-1-i)) | (1<<(n-1-j)));\n                }\n            }\n        }\n        int x=(1<<n)-1;\n        for(int i=1; i<=x; i++){\n            int flag=0;\n            for(int j=0; j<p.size(); j++){\n                if((i & (p[j]))==p[j]){\n                    flag=1;\n                }\n            }\n            ans+=flag==0;\n        }\n        return ans;\n    }\n};\n```
['C++']