Koko has several piles of bananas and h hours. At an integer speed k, she spends one hour consuming up to k bananas from one pile.
Return the smallest speed that lets her finish every pile within h hours.
Inputpiles = [3, 6, 7, 11], h = 8
Output4
At speed 4, the piles take 1, 2, 2, and 3 hours, totaling 8. Speed 3 takes 10 hours, so 4 is the smallest speed that works.
Inputpiles = [30, 11, 23, 4, 20], h = 5
Output30
Five piles in five hours means each pile must fit in one hour. The largest pile has 30 bananas, so the minimum speed is 30.
1 ≤ piles.length ≤ h ≤ 100,0001 ≤ piles[i] ≤ 1,000,000,000