1 minute read

You are given a list of integers piles and an integer k. piles[i] represents the number of bananas on pile i. On each hour, you can choose any pile and eat r number of bananas in that pile. If you pick a pile with fewer than r bananas, it still takes an hour to eat the pile.

Return the minimum r required such that you can eat all the bananas in less than or equal to k hours.


  • n ≤ 100,000 where n is the length of piles
  • n ≤ k



Example 1


  • piles = [6, 4, 3]
  • k = 5


  • answer = 3


At r = 3 bananas per hour, we can eat the first pile in 2 hours, eat the second in 2 hours, and eat the last pile in 1 hour.


Leave a comment