FastPrepMaximum Candies per Child
Problems/Maximum Candies per Child

Maximum Candies per Child

Amazon logoAmazon● MediumINTERNONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The judged objective and one-pile-per-child portion rule match the visible interview report. Explicit bounds and the impossible-case result complete the contract at about 98%.

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) → int

Examples

Example 1

piles = [5,8,6]children = 3return = 5

Portions of sizes 5, 5, and 5 can be formed; size 6 produces only two portions.

Example 2

piles = [2,5]children = 11return = 0

Only seven one-candy portions exist.

Constraints

  • 1 <= piles.length <= 200000
  • 1 <= piles[i] <= 10^9
  • 1 <= children <= 10^14

Source note: Interview prompt excerpt preserved as source evidence.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
public int maximumCandiesPerChild(int[] piles, long children) {
    // Write your code here.
}
Checking account…