> For the complete documentation index, see [llms.txt](https://chiragjain.gitbook.io/neetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chiragjain.gitbook.io/neetcode/875-koko-eating-bananas/code.md).

# CODE

```python
class Solution:
    def minEatingSpeed(self, piles: List[int], h: int) -> int:
        # Koko can eat minimum of 1 banan OR max(piles) in one seating
        l, r = 1, max(piles)     
        while l <= r:
            # Mid way between the min and max banana Koko can eat in one 
            # seating
            k = (l + r) // 2
            # Num of hours req by Koko to eat all piles at rate k
            h_r = sum(math.ceil(p / k) for p in piles)
            # If Koko is eating fast, decrease the max banana koko
            # should eat
            if h_r <= h:
                r = k - 1
            # not eating fast enough, increase the min banana koko 
            # should eat
            else:
                l = k + 1
        # The result is the min banana
        return l
            
                
        
```
