Minimum Eating Speed
Your daughter, Alex, has just come home with a bag full of candy after a long night of trick-or-treating. Before going to sleep, Alex places the candy in numPiles piles with the i-th pile containing candyPiles[i] number of candies.
After arranging the candies into piles, Alex announces she is going to sleep for numHours hours.
Your plan is to eat all the candy before Alex wakes up in numHours. You can eat c candies per hour, but in each hour you will only eat candy from a single pile. If a pile contains fewer than c candies, you will only eat the number of candies in that pile and you will wait until the next hour to eat more candy.
Having a little bit of self-restraint your goal is to calculate the smallest number of candies c you need to eat per hour in order to finish all the candy before Alex wakes up again.
Complete the function minimumEatingSpeed in the editor.
minimumEatingSpeed has the following parameters:
int[] candyPiles: an array of integers representing the number of candies in each pileint numHours: the number of hours Alex will be asleep for
Returns
int: the smallest number of candies c that you need to eat per hour in order to finish all the candies before Alex wakes up
1Example 1
To finish all the candies in 8 hours, you can eat at the following speed:
- Hour 1: Eat 6 candies from the pile with 17 candies, 11 remain.
- Hour 2: Eat 6 candies from the pile with 11 candies, 5 remain.
- Hour 3: Eat 5 candies from the pile with 5 candies, 0 remain.
- Hour 4: Eat 6 candies from the pile with 9 candies, 3 remain.
- Hour 5: Eat 3 candies from the pile with 3 candies, 0 remain.
- Hour 6: Eat 4 candies from the pile with 4 candies, 0 remain.
- Hour 7: Eat 6 candies from the pile with 11 candies, 5 remain.
- Hour 8: Eat 5 candies from the pile with 5 candies, 0 remain.
The smallest number of candies you need to eat per hour is 6.