[C++] || Easy To Understand
Approach\n Describe your approach to solving the problem. \n- Used the basic approach of finding all subsets (Take/Not Take).\n- But at the time of adding a new
# Approach\n<!-- Describe your approach to solving the problem. -->\n- Used the basic approach of finding all subsets (Take/Not Take).\n- But at the time of adding a new element in subset, we will check if the subset will remain Beautiful after adding the element.\n    - If subset still Beautiful, process futher.\n    - If the new element made the subset "Ugly", no need to check futher.\n- If we reach the end of nums means we got our Beautiful subset and increment the `ans` count.    \n\n---\n\n- Taken a variable `take` to run the "checking" part code only if new element is added, to save time.\n\n# Code\n```\nclass Solution {\npublic:\n    int ans=0;\n\n    void solve(vector<int> &nums,int target,int idx,vector<int> &temp,bool take){\n        //only process if new element taken\n        if(take){\n            //latest element added is last element of "temp"\n            int addedElement = temp[temp.size()-1];\n            //subtract all previously added elements from latest\n            for(int i=0;i<temp.size()-1;i++){\n                if(abs(addedElement - temp[i]) == target){\n                    //no need to process futher\n                    return;\n                }\n            }\n        }\n\n        //base case\n        if(nums.size() == idx){\n            //got a beautiful subset\n            ans++;\n            return;\n        }\n\n        //take\n        temp.push_back(nums[idx]);\n        solve(nums,target,idx+1,temp,true);\n        \n        //not take\n        temp.pop_back();\n        solve(nums,target,idx+1,temp,false);\n    }\n\n    int beautifulSubsets(vector<int>& nums, int k) {\n        vector<int> temp;\n        solve(nums,k,0,temp,false);\n        //Remove the empty subset count from ans\n        return ans-1;\n    }\n};\n```
['C++']