LeetCode 875 Koko Eating Bananas - Why Naive Fails

The trap

Try each possible speed from 1 to max(piles). For each speed, calculate the total hours needed.

There are up to 10910^9 possible speeds. Checking each takes O(n)O(n). Total: O(nmax(piles))O(n \cdot \max(piles)).

That's up to 101310^{13} operations. Far too slow.