15. Chocolate Distribution Problem
β GFG solution to the Chocolate Distribution Problem: minimize the difference between maximum and minimum chocolates distributed using sorting and sliding window technique. π
π§© Problem Description
π Examples
Example 1
Input: arr = [3, 4, 1, 9, 56, 7, 9, 12], m = 5
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].Example 2
Input: arr = [7, 3, 2, 4, 9, 12, 56], m = 3
Output: 2
Explanation: The minimum difference between maximum chocolates and minimum chocolates is 4 - 2 = 2
by choosing following m packets: [3, 2, 4].Example 3
π Constraints
β
My Approach
Sorting + Sliding Window
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated