Javascript recursive solution beats 100%
js\nvar minSum = Number.MAX_SAFE_INTEGER;\n\nvar recur = function(curIdx, subsets, nums, k, countOfEveryGroup, currentSum) {\n    if (curIdx === nums.length && 
```js\nvar minSum = Number.MAX_SAFE_INTEGER;\n\nvar recur = function(curIdx, subsets, nums, k, countOfEveryGroup, currentSum) {\n    if (curIdx === nums.length && currentSum < minSum) {\n        minSum = currentSum;\n        return;\n    }\n    var curNum = nums[curIdx];\n    for (var subsetIdx = 0; subsetIdx < subsets.length; subsetIdx++) {\n        var subset = subsets[subsetIdx];\n        if (subset.length >= countOfEveryGroup || subset.indexOf(curNum) !== -1) continue;\n        var minOfCurSubSet = Math.min(...subset);\n        var maxOfCurSubSet = Math.max(...subset);\n        subset.push(curNum);\n        var shouldAddToSum = 0;\n        if (curNum > maxOfCurSubSet) {\n            shouldAddToSum += (curNum - maxOfCurSubSet);\n        } else if (curNum < minOfCurSubSet) {\n            shouldAddToSum += (minOfCurSubSet - curNum);\n        }\n        var newSum = currentSum + shouldAddToSum;\n        if (newSum < minSum) {\n            recur(curIdx + 1, subsets, nums, k, countOfEveryGroup, newSum);\n        }\n        subset.pop();\n    }\n    if (subsets.length < k) {\n        var newSubset = [curNum];\n        subsets.push(newSubset);\n        recur(curIdx + 1, subsets, nums, k, countOfEveryGroup, currentSum);\n        subsets.pop();\n    }\n};\n\n/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar minimumIncompatibility = function(nums, k) {\n    if (k === 0) return -1;\n    var numsCount = nums.length;\n    var countOfEveryGroup = numsCount / k;\n    var numCountArr = new Array(16).fill(0);\n    nums.forEach(num => numCountArr[num]++);\n    if (numCountArr.some(count => count > k)) return -1;\n    if (k === 1) return Math.max(...nums) - Math.min(...nums);\n    minSum = Number.MAX_SAFE_INTEGER;\n    \n    recur(0, [], nums, k, countOfEveryGroup, 0);\n    return minSum;\n};\n```
['Recursion', 'JavaScript']