Problem Statement
You have a certain number of chocolates packets, each containing a different number of chocolates. You want to distribute these chocolates among a given number of children. The objective is to ensure a fair distribution such that each child receives exactly one packet, and the difference between the number of chocolates in the packets with the most and least chocolates is minimized. The task is to find the minimum difference.
Input:
- An array
chocolates
of length n (1≤ n ≤ 10^5) representing the number of chocolates in each packet. - An integer
students
(1≤ students ≤ n) representing the number of children.
Output:
- An integer representing the minimum difference between the number of chocolates in the packets with the most and least chocolates after distribution.
Example:
Input:
chocolates = {7, 3, 2, 4, 9, 12, 56}
students = 3
Output:
2
Explanation:
The chocolates can be distributed among the children as follows: {2, 3, 4}. In this case, the difference between the packet with the most chocolates (4), and the one with the least chocolates (2) is minimized, resulting in a minimum difference of 2.