dfs + bitmask + 2 pruning points
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def minimumIncompatibility(self, nums: List[int], k: int) -> int:\n        N = len(nums)\n        if k == N:\n            return 0\n        S = N // k\n        buckets = [0 for _ in range(k)]\n        memo = {}\n        def get_current_score():\n            cnt = 0\n            for i in range(k):\n                val = buckets[i]\n                cnt += (val.bit_length() - 1) - ((val ^ (val - 1)).bit_length() - 1)\n            return cnt\n\n        res = float(inf)\n        def dfs(index):\n            nonlocal res\n            score = get_current_score()\n            if score >= res: # prune 1\n                return\n            if index == N:\n                res = min(res, score)\n                return\n\n            for i in range(k):\n                if buckets[i].bit_count() < S and (buckets[i] & (1 << nums[index]) == 0):\n                    buckets[i] |= (1 << nums[index])\n                    dfs(index+1)\n                    buckets[i] ^= (1 << nums[index])\n                if buckets[i] == 0: # prune 2\n                    break\n        dfs(0)\n        return res if res != float(inf) else -1\n\n```
['Python3']