6

Chocolate Distribution Problem

 1 year ago
source link: https://www.geeksforgeeks.org/videos/chocolate-distribution-problem-1/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Chocolate Distribution Problem

August 06, 2023 |1.0K Views
Chocolate Distribution Problem
Sorting, Problem of the Day, Data Structures and Algorithms
 Save  Share  1 Like
Description
Discussion

In this video, we are given an array A[ ] of positive integers of size N, 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 among M students such that :
1. Each student gets exactly one packet.
2. The difference between maximum number of chocolates given to a student and minimum number of chocolates given to a student is minimum.

Example 1:

Input:
N = 8, M = 5
A = {3, 4, 1, 9, 56, 7, 9, 12}

Output: 6

Explanation: The minimum difference between maximum chocolates and minimum chocolates is 9 - 3 = 6 by choosing following M packets :{3, 4, 9, 7, 9}.

Give the problem a try before going through the video. All the best!!!

Problem Link: https://practice.geeksforgeeks.org/problems/chocolate-distribution-problem3825/1

Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp-compiler/91d22e05-5467-47fb-a3e4-13fa836b8670

Read More

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK