Practice/Meta/Leetcode 2226. Maximum Candies Allocated to K Children
CodingOptional
You are distributing candy to children from several bags. You have an array candies where candies[i] represents the number of candies in the i-th bag. You need to distribute candies to exactly k children.
You can split any bag into smaller portions, but you cannot combine candies from different bags. Each child must receive exactly the same number of candies. Your goal is to maximize the number of candies each child receives.
Find the maximum number of candies each child can get, or return 0 if it's impossible to distribute candies equally to all k children.
k children must receive exactly the same number of candiesExample 1:
` Input: candies = [5, 8, 6], k = 3 Output: 5 Explanation: We can distribute 5 candies to each of 3 children:
Example 2:
Input: candies = [2, 5], k = 11 Output: 0 Explanation: Total candies = 7, but we need to serve 11 children. Even giving 0 candies won't work, so we return 0.
Example 3:
` Input: candies = [4, 7, 5], k = 4 Output: 3 Explanation: We can give 3 candies to each of 4 children: