Question: For a given array of N integers (where each value represents the number of chocolates in a packet and array size as a number of



For a given array of N integers (where each value represents the number of chocolates in a packet and array size as a number of packets) and M students, write a program t distribute the chocolate packets as below and print the result of it. 1) Each student gets one packet. 2) The difference between the number of chocolates in packet with maximum chocolates and packet with minimum chocolates given to the students is minimum. For example,if input array=5,9,7,11,14,17 and Students =3 so output =4 because 1) Each student gets one packet. 2) The difference between the number of chocolates in packet with maximum chocolates and packet with minimum chocolates given to the students is minimum. For example, if input array =5,9,7,11,14,17 and Students =3 so output=4 because minimum difference elements of array are 5,7,9 which has differene =2 so we consider them as packet with minimum chocolates for 3 students and difference between the number of chocolates in pack with maximum chocolates =95=4 . Limport java.util.*; 2. class MinDiffNum \{ static int findMinDiff(int arr[], int n, int m ) \{ //write your code here \} public static void main(String[] args) \{ MinDiffNum obj = new MinDiffNum(); Scanner in = new Scanner(System.in); int n=in. nextInt(); int m=in. nextInt(); int arr[]= new int [n]; for (int i=0;i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
