DFS
```\nclass Solution {\npublic:\n    \n    int gmin = INT_MAX;\n    \n    int dfs(int e,int ma,int mi,vector &nums,int isUsed, vector& b,int nidx,int bidx,int k,
```\nclass Solution {\npublic:\n    \n    int gmin = INT_MAX;\n    \n    int dfs(int e,int ma,int mi,vector<int> &nums,int isUsed, vector<int>& b,int nidx,int bidx,int k,int sz,int prev){\n        \n        if(bidx == k){\n            gmin = min(e,gmin);\n            return e;\n        }\n        if( e > gmin) return INT_MAX;\n        if(bitset<32>(b[bidx]).count() == sz){\n            return dfs(e + ma - mi,INT_MIN,INT_MAX,nums,isUsed,b,0,bidx+1,k,sz,-1);\n        }\n        \n        \n        \n        if(nidx == nums.size()) return INT_MAX;\n        \n        \n        int ans = INT_MAX;\n        \n        for(int i = nidx; i < nums.size(); i++){\n            \n            if(isUsed&(1<<i) || (b[bidx]&(1<<nums[i]) || nums[i] <= prev)) continue;\n            \n            \n            \n            b[bidx]^=(1<<nums[i]);\n            isUsed ^= (1<<i);\n            ans = min(ans,dfs(e,max(ma,nums[i]),min(mi,nums[i]),nums,isUsed,b,i+1,bidx,k,sz,nums[i]));\n            \n            b[bidx]^=(1<<nums[i]);\n            isUsed ^= (1<<i);\n            \n            if(b[bidx] == 0) break;\n            \n        }\n   \n        \n        return ans;\n    }\n    \n    \n    int minimumIncompatibility(vector<int>& nums, int k) {\n          vector<int> b(k);\n        sort(nums.begin(),nums.end());\n        //return 0;\n        int ans = dfs(0,INT_MIN,INT_MAX,nums,0,b,0,0,k,nums.size()/k,-1);\n        return ans != INT_MAX?ans:-1;\n    }\n};
[]