mediumArrayGreedyHash Table 0 views

Minimum Number of Groups to Create a Valid Assignment

You are given a collection of numbered balls and instructed to sort them into boxes for a nearly balanced distribution.

You are given a collection of numbered balls and instructed to sort them into boxes for a nearly balanced distribution. There are two rules you must follow:

​Return the fewest number of boxes to sort these balls following these rules.

Minimum Number of Groups to Create a Valid Assignment diagram

Example 1

Input: balls = [3,2,3,2,3]

Output: 2

Explanation: We can sort balls into boxes as follows: The size difference between the two boxes doesn't exceed one.

Example 2

Input: balls = [10,10,10,3,1,1]

Output: 4

Explanation: We can sort balls into boxes as follows: You can't use fewer than four boxes while still following the rules. For example, putting all three balls numbered 10 in one box would break the rule about the maximum size difference between boxes.

Constraints

  • 1 <= nums.length <= 10^5
  • 1 <= nums[i] <= 10^9

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.