Maximum Candies per Child
Problem statement
You are given positive candy-pile sizes and a positive number of children. A pile may be split into smaller portions, but portions from different piles may not be combined.
Every child must receive the same positive number of candies from one portion. Return the maximum candies each child can receive. Return 0 when the piles cannot give every child even one candy.
Function
maximumCandiesPerChild(piles: int[], children: long) → intExamples
Example 1
piles = [5,8,6]children = 3return = 5Portions of sizes 5, 5, and 5 can be formed; size 6 produces only two portions.
Example 2
piles = [2,5]children = 11return = 0Only seven one-candy portions exist.
Constraints
1 <= piles.length <= 2000001 <= piles[i] <= 10^91 <= children <= 10^14
Source note: Interview prompt excerpt preserved as source evidence.