Java backtracking solution with optimizations [beats 11.11%]
\nclass Solution {\n    \n    int minIncompatability = Integer.MAX_VALUE;\n    \n    public int minimumIncompatibility(int[] nums, int k) {\n        if (nums.le
```\nclass Solution {\n    \n    int minIncompatability = Integer.MAX_VALUE;\n    \n    public int minimumIncompatibility(int[] nums, int k) {\n        if (nums.length%k != 0) return -1;\n        int elementsPerSubset = nums.length / k;\n        List<Set<Integer>> currentState = new ArrayList<>();\n        for (int i = 0; i < k; i++) {\n            currentState.add(new HashSet<Integer>());\n        }\n        recHelper(0, nums, elementsPerSubset, k, currentState);\n        \n        return minIncompatability == Integer.MAX_VALUE ? -1 : minIncompatability;\n    }\n    \n    public List<Set<Integer>> deepCopyState(List<Set<Integer>> currentState) {\n        List<Set<Integer>> copyOfCurrentState = new ArrayList<>(); \n        for (Set<Integer> s : currentState) {\n            copyOfCurrentState.add(new HashSet<>(s)); \n        } \n        return copyOfCurrentState;\n    }\n    \n    public int calculateCurrentInCompatability(List<Set<Integer>> solution) {\n        int sum = 0; \n        for (Set<Integer> set : solution) {\n            if (set.size() > 0) sum += set.stream().max(Integer::compare).get() - set.stream().min(Integer::compare).get(); \n        } \n        return sum;\n    }\n    \n    public void recHelper(int currentIndex, int[] nums, int elementsPerSubset, int k, List<Set<Integer>> currentState) {\n        if (currentIndex == nums.length) {\n            int inCompatability = calculateCurrentInCompatability(currentState);\n            if (inCompatability < minIncompatability) minIncompatability = inCompatability;\n        }\n        else if (currentIndex < nums.length) {\n            for (int i = 0; i < k; i++) {\n                List<Set<Integer>> copyOfCurrentState = deepCopyState(currentState);\n                Set<Integer> set = copyOfCurrentState.get(i);\n                if (set.size() < elementsPerSubset && !set.contains(nums[currentIndex])) {\n                    if (set.size() == 0) while(i < k && copyOfCurrentState.get(i).isEmpty()) i++;\n                    set.add(nums[currentIndex]);\n                    if (calculateCurrentInCompatability(copyOfCurrentState) <= minIncompatability)\n                        recHelper(currentIndex+1, nums, elementsPerSubset, k, copyOfCurrentState);\n                }\n            }            \n        }\n    }\n}\n```
[]