498. Maximum Candies Allocated to K Children

MediumBinary SearchBinary Search on AnswerArray

Given piles of candies (each pile has a count) and k children, you may split piles but not merge them; every child must receive the same number of candies (you may discard leftovers). Return the maximum number of candies each child can get, or 0 if it is impossible to give each child at least one. Input: '[candies], k'.

Input: '[candies], k'.

Output: Integer — the maximum candies per child.

Examples

Example 1
Input: [5,8,6], 3
Output: 5
Explanation: Each child can get 5.
Example 2
Input: [2,5], 11
Output: 0
Explanation: Not enough candies.
Example 3
Input: [10], 1
Output: 10
Explanation: One child takes all.

Constraints

Asked by

GoogleOracleAmazonBloombergMicrosoftMeta
Solve this problem in the editor →