piles, where piles[i] is the number of candies in the i-th pile. Any pile may be split into as many smaller parts as you like, but candies from different piles can never be combined.
There are children children. Every child must get the same number of candies, and all of a child's candies must come from a single pile. Some candies, or even whole piles, may stay undistributed.
Return the largest number of candies each child can get. If there is not even one candy for everybody, return 0.piles=[9, 4, 7], children=4 → 4
With 4 candies each, the pile of 9 gives two portions and the piles of 4 and 7 one each, four in total. With 5 each there are only two portions (from 9 and from 7), not enough.
piles=[3, 2], children=6 → 0
There are only 5 candies for 6 children, so not everyone can get even one; the answer is 0.
piles=[12], children=5 → 2
The single pile of 12 splits into five portions of 2 (two candies are left over); portions of 3 would give only four.
piles.length ≤ 10⁵piles[i] ≤ 10⁷children ≤ 10¹²piles=[9, 4, 7], children=4
4
Run checks the first 3 tests in your browser. Submit checks all 83 tests on the server, hidden ones included.