Skip to content
Decoder

Maximum Candies Allocated to K Children

Medium

Problem

You have piles of candies, candies[i] in pile i. You can split a pile into smaller piles, but you cannot merge two piles. Give each of k children one pile, all of the same size. Some piles may go unused. Return the maximum number of candies each child can get (0 if you cannot give everyone even one candy).

Example 1

Input
candies = [5, 8, 6], k = 3
Output
5
Why
piles of 5: one from 5, one from 8, one from 6

Example 2

Input
candies = [2, 5], k = 11
Output
0
Why
only 7 candies for 11 children

Example 3

Input
candies = [4, 7, 5], k = 4
Output
3

Constraints

  • 1 <= candies.length <= 10^5
  • 1 <= candies[i] <= 10^7
  • 1 <= k <= 10^12

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.