items and a number group_count. Split all the elements into exactly group_count groups of equal size so that no group contains two equal numbers.
The spread of a group is its largest element minus its smallest. Return the smallest possible total spread over all groups, or -1 if the elements cannot be split this way.items=[3, 1, 3, 2], group_count=2 → 3
The two 3s must end up in different groups. Groups [1, 3] and [2, 3] give 2 + 1 = 3, while [1, 2] and [3, 3] is not allowed.
items=[2, 2, 2, 1], group_count=2 → -1
Three 2s cannot be spread over two groups with at most one 2 in each.
items=[4, 1, 6, 2, 5, 3], group_count=3 → 3
items=[3, 1, 3, 2], group_count=2
3
Run checks the first 3 tests in your browser. Submit checks all 66 tests on the server, hidden ones included.