[Python] DFS + Branch and Bound
\nclass Solution:\n    def minimumIncompatibility(self, nums: List[int], k: int) -> int:\n        nums.sort()\n        n = len(nums)\n        bucket = [set() fo
```\nclass Solution:\n    def minimumIncompatibility(self, nums: List[int], k: int) -> int:\n        nums.sort()\n        n = len(nums)\n        bucket = [set() for _ in range(k)]\n        self.ans = math.inf\n        def dfs(i):\n            res = 0\n            for b in bucket:\n                if b:\n                    res += max(b) - min(b)\n            if res >= self.ans:\n                return\n            if i == n:\n                self.ans = min(self.ans, res)\n            else:\n                seen = set()\n                for b in bucket:\n                    if tuple(b) not in seen and nums[i] not in b and len(b) < n // k:\n                        b.add(nums[i])\n                        dfs(i + 1)\n                        b.discard(nums[i])\n                        seen.add(tuple(b))\n        dfs(0)\n        return -1 if self.ans == math.inf else self.ans\n```
[]