0 ms, binary search+DFS, clean and easy to understand
This solution is inspired by https://leetcode.com/problems/find-minimum-time-to-finish-all-jobs/discuss/1010057/JavaPython-Binary-Search-100\n\n\nfunc minimumIn
This solution is inspired by https://leetcode.com/problems/find-minimum-time-to-finish-all-jobs/discuss/1010057/JavaPython-Binary-Search-100\n\n```\nfunc minimumIncompatibility(nums []int, k int) int {\n    cnts := make([]int, len(nums)+1, len(nums)+1) //1 <= nums[i] <= nums.length\n    for _, n := range nums {if cnts[n]++; cnts[n] > k {return -1}} //no two equal elements in the same subset.\n\n    setlen := len(nums)/k\n    targetSum := 0 \n    \n    var dfs func(cnti, j, sum int, sets [][]int) bool\n    dfs = func(cnti, j, sum int, sets [][]int) bool {   \n        if len(sets[j]) == setlen {\n            if sum += sets[j][setlen-1] - sets[j][0]; sum > targetSum {return false} //make the lower bound l higher\n            \n            if j++; j == k {return true} //smaller targetSum is possible, make the upper bound r lower\n            \n            cnti = 1\n        }\n        \n        for i := cnti; i < len(cnts); i++{\n            if cnts[i] == 0 {continue}\n            \n            l := len(sets[j])\n            if l > 0 && sum+i-sets[j][0] > targetSum {return false} //make the lower bound l higher\n            \n            cnts[i]--\n            sets[j] = append(sets[j], i)\n            if dfs(i+1, j, sum, sets) {\n\t\t\t\tsets[j] = sets[j][:l]\n\t\t\t\tcnts[i]++\n\t\t\t\treturn true\n\t\t\t}\n            \n            sets[j] = sets[j][:l]          \n            cnts[i]++\n            if l == 0 {return false}\n        }\n        \n        return false\n    }\n    \n    l, r := 0, 120 //1 <= k <= nums.length <= 16, so the upper bound is 120 = (16-1)*8\n    for l < r{\n        targetSum = (l+r)>>1\n        if dfs(1, 0, 0, make([][]int, k, k)) {\n            r = targetSum\n        }else{\n            l = targetSum+1\n        }\n    }\n    \n    return l\n}\n```
[]