0(2^n) solution in c++
Intuition\nsimple dp and bitmasking \n\n# Approach\n1. first count how many combination are possible \n2. for this i run loop from 1 to (1<<n)and check necesser
# Intuition\nsimple dp and bitmasking \n\n# Approach\n1. first count how many combination are possible \n2. for this i run loop from 1 to (1<<n)and check necessery  condition \n3. store differnce and mask in vector v\n4. reun recurison \n\n\n# Complexity\n- Time complexity:\n0(2^n)\n\n- Space complexity:\n0(2^n)\n\n# Code\n```\nclass Solution {\npublic:\n    int dp[1001000];\n    int solve(int mask,vector<vector<int>>&v,int n){\n      \n        if(mask==((1<<n)-1)) return 0;\n        //if(i==v.size()) return 1e9;\n        if(dp[mask]!=-1) return dp[mask];\n        int ans=1e9;\n        for(int i=0;i<v.size();i++){\n            if((mask&v[i][0])==0){\n                 ans=min(ans,v[i][1]+solve(mask|v[i][0],v,n));\n            }\n        }\n        return dp[mask]=ans;\n    }\n    int minimumIncompatibility(vector<int>& nums, int k) {\n       memset(dp,-1,sizeof(dp));\n        int n=nums.size();\n        vector<vector<int>>v;\n        int r=n/k;\n        for(int i=0;i<(1<<n);i++){\n            if(__builtin_popcount(i)==(n/k)){\n                int maxnum=-1e9,minnum=1e9;\n                set<int>st;\n                for(int j=0;j<nums.size();j++){\n                    if((i&(1<<j))!=0){\n                        st.insert(nums[j]);\n                        maxnum=max(maxnum,nums[j]);\n                        minnum=min(minnum,nums[j]);\n                    }\n                }\n                if(st.size()==(n/k)) {\n                    v.push_back({i,maxnum-minnum});\n                }\n\n            }\n        }\n        cout<<v.size()<<endl;\n        return solve(0,v,n)==1e9?-1:solve(0,v,n);\n    }\n};\n```
['C++']