3
6
7
11
[0][1][2][3]
hours per pile
·
·
·
·
[0][1][2][3]
Brute force · try every speed
▸1given piles, H2for k = 1, 2, 3, …:3 hours = Σ ceil(pile / k)4 if hours ≤ H: return k5// first fit is the minimum
state
- piles[3, 6, 7, 11]
- H8
Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.
Try one problemGiven piles of bananas and a fixed number of hours, find the minimum constant eating speed (bananas per hour) that lets you finish all piles within the hour limit. Each hour you eat from a single pile, and if a pile has fewer bananas than your speed you still spend the whole hour on it.
▸1given piles, H2for k = 1, 2, 3, …:3 hours = Σ ceil(pile / k)4 if hours ≤ H: return k5// first fit is the minimum
line 1Koko eats one pile per hour at speed k apples/hour (a small pile still burns the full hour). Finish ALL piles within H = 8 hours with the SMALLEST k. Brute: try k = 1, 2, 3, … the first k that fits is the answer.