Imagine you're a parent trying to fairly distribute bags of cookies among your children for a school event. You have several bags, each containing different amounts of cookies, and you need to give all bags to your k children.
Here's the challenge: each bag must go to exactly one child (you can't split a bag), and you want to minimize the maximum number of cookies any single child receives. This creates the most "fair" distribution possible.
Given an integer array cookies where cookies[i] represents the number of cookies in the i-th bag, and an integer k representing the number of children, return the minimum possible unfairness.
The unfairness is defined as the maximum total cookies obtained by any single child in the distribution.
Input & Output
Visualization
Time & Space Complexity
For each of n bags, we try k children, leading to k^n total combinations
Recursion stack depth equals number of bags
Constraints
- 2 โค cookies.length โค 8
- 1 โค cookies[i] โค 105
- 2 โค k โค cookies.length
- All bags must be distributed - no bag can be left unassigned