Java O(k^n) solution with early termination (9ms 98%)
This problem is asking us to do the reversal of  "merging k sorted lists into one sorted list".\nIn other words, considering we are "distributing a sorted list 
This problem is asking us to do the reversal of  "merging k sorted lists into one sorted list".\nIn other words, considering we are "distributing a sorted list to k sorted lists".\nThe time complexity is O(k^n) since each number can have k choices.\n\n```\nclass Solution {\n    int ans = Integer.MAX_VALUE;\n    void helper(int[] nums, int s, LinkedList<LinkedList<Integer>> buckets, int k, int size, int total) {\n        if(total >= ans) return; //early termination\n        if (s == nums.length) {\n            ans = total; // With early termination, Math.min() is no longer needed.\n        } else {\n            // distribute current number to an existing bucket\n            for (int i=0; i<buckets.size(); i++) {\n                LinkedList<Integer> bucket = buckets.get(i);\n                if (bucket.size() < size && bucket.peekLast() < nums[s]) {\n                    int distance = nums[s] - bucket.peekLast();\n                    bucket.addLast(nums[s]);\n                    helper(nums, s+1, buckets, k, size, total+distance);\n                    bucket.removeLast();\n                }\n            }\n            // distribute current number to an empty bucket\n            if (buckets.size() < k) {\n                LinkedList<Integer> bucket = new LinkedList<>();\n                bucket.add(nums[s]);\n                buckets.addLast(bucket);\n                helper(nums, s+1, buckets, k, size, total);\n                buckets.removeLast();\n            }\n        }\n    }\n    \n    public int minimumIncompatibility(int[] nums, int k) {\n        Arrays.sort(nums);\n        helper(nums, 0, new LinkedList<>(), k, nums.length/k, 0);\n        return ans == Integer.MAX_VALUE?-1: ans;\n    }\n}\n```
[]