You have k children and n bags of cookies. Distribute all bags among k children such that the maximum number of cookies any child gets is minimized. Return that minimum maximum.
Use backtracking over all assignments. Try giving each cookie bag to each child. Prune branches where a child's current total already exceeds our best answer.
- Maintain an array children[] of size k tracking each child's total.
- At each bag index, try assigning it to each child.
- After assigning, recurse to the next bag; then backtrack.
- When all bags are distributed, update the global minimum with max(children[]).
- Time Complexity: O(k^n) worst case with pruning
- Space Complexity: O(k + n) — children array + stack