[Python3] DP top down with comments
python\n    def minimumIncompatibility(self, A: List[int], k: int) -> int:\n        n = len(A) # <= 16\n        if n == k: return 0 # each subset has just one i
```python\n    def minimumIncompatibility(self, A: List[int], k: int) -> int:\n        n = len(A) # <= 16\n        if n == k: return 0 # each subset has just one integer\n        if n % k != 0: return -1\n        c = Counter(A)\n        if any(x > k for x in c.values()): return -1\n        if k == 1: return max(A) - min(A)\n        gs = n // k # group size\n        \n        @lru_cache(None)\n        def f(A, k):\n            # there is euqal elements for one subset, invalid, set to float(\'inf\')\n            if 1 == k: return max(A) - min(A) if len(set(A)) == len(A) else float(\'inf\')\n            res, us = float(\'inf\'), set(A)\n            for g in itertools.combinations(us, gs):\n                s, can, B = Counter(g), max(g) - min(g), list(A)\n                for x in g: B.remove(x)\n                res = min(res, can + f(tuple(B), k - 1))\n            return res\n        res = f(tuple(A), k)\n        return -1 if res == float(\'inf\') else res\n```\t\t
[]