Gamified challenge · Binary search on the answer
piles[i] parcels wait at stop i, and the courier has h hours (always at least one hour per stop). At speed k the courier hands over up to k parcels an hour and spends each hour at one stop, even if that stop runs out early, so stop i takes ⌈piles[i] / k⌉ hours.
Write minSpeed(piles, h) that returns the smallest whole speed k ≥ 1 that delivers everything within h hours.
Example: piles = [3, 6, 7, 11], h = 8. Speed 4 takes 1 + 2 + 2 + 3 = 8 hours, but speed 3 takes 1 + 2 + 3 + 4 = 10, so the answer is 4.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google