Practice Minimum Incompatibility
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given an integer array nums and an integer k. You are asked to distribute this array into k subsets of equal size such that there are no two equal elements in the same subset. A subset's incompatibility is the difference between the maximum and minimum elements in that array. Return the minimum possible sum of incompatibilities of the k subsets after distributing the array optimally, or return -1 if it is not possible. A subset is a group integers that appear in the array with no particular order.
Source: Minimum Incompatibility on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [1,2,1,4], k = 2
4
# Example 2
nums = [6,3,8,1,3,1,2,2], k = 4
6
# Example 3
nums = [5,3,3,6,3,3], k = 3
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Incompatibility.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.