# Java: Chocolate Distribution Problem

Level : Intermediate
Mentor: Shailendra Chauhan
Type : GuidedLab
Points : 10
Duration : 00:30:00

#### Lab Details

Problem Statement:

Given an array of N integers where each value represents the number of chocolates in a packet.

Each packet can have a variable number of chocolates. There are m students, the task is

to distribute chocolate packets such that:

Each student gets one packet.

The difference between the number of chocolates in the packet with maximum

chocolates and the packet with minimum chocolates given to the students is minimum.

Input:

``````arr[] = {7, 3, 2, 4, 9, 12, 56} , m = 3
``````

Output:

``````Minimum Difference is 2
We have seven packets of chocolates and we need to pick three packets for 3
students. If we pick 2, 3 and 4, we get the minimum difference between the maximum
````and minimum packet sizes.````
Self-paced Membership
• 22+ Video Courses
• 800+ Hands-On Labs
• 400+ Quick Notes
• 55+ Skill Tests
• 45+ Interview Q&A Courses
• 10+ Real-world Projects
• Career Coaching Sessions
• Email Support
Upto 60% OFF
Still have some questions? Let's discuss.