Koko loves bananas. There are piles.length piles, and the i-th pile has piles[i] bananas. The guards have gone and will come back in h hours.
Koko decides her eating speed k (bananas per hour). Each hour she picks a pile and eats k bananas from it. If the pile has fewer than k bananas, she eats all of them and will not eat any more during that hour.
Return the minimum integer speed k such that she can finish every pile within h hours.
Because she can only eat from one pile per hour, a pile of p bananas always takes ceil(p / k) hours at speed k.
Input / output
piles: int[], h: intint — the minimum feasible speed1 <= piles.length <= 10000piles.length <= h <= 10000000001 <= piles[i] <= 1000000000The hours-needed function is monotonic in k (faster is never slower to finish). How does that monotonicity let you binary-search the answer instead of trying every speed?