You are given cookies, an array where cookies[i] is the number of cookies inside the i-th bag. There are k children, and each entire bag must be given to exactly one child — no splitting is allowed.
The unfairness of a distribution is defined as the maximum total number of cookies assigned to any single child.
Your goal is to distribute all cookie bags among the children such that this unfairness value is as small as possible.
Return that minimum unfairness.\
Input: cookies = [5,12,7,5], k = 2
Output: 17
Explanation:
One optimal distribution: Child 1 → [12,5] → 17 cookies Child 2 → [7,5] → 12 cookies Unfairness = max(17,12) = 17 No distribution can make the max value lower than 17. Example 2
Input: cookies = [4,4,4,4], k = 4
Output: 4
Explanation:
Each child gets one bag → max = 4.
Accepted:
Submission: