coding•DSA & Problem Solving•Binary Search & Optimization
Koko Eating Bananas
Problem Statement
Koko loves to eat bananas. There are `n` piles of bananas, the `i-th` pile has `piles[i]` bananas. The guards have gone and will come back in `h` hours.
Koko can decide her bananas-per-hour eating speed of `k`. Each hour, she chooses some pile of bananas and eats `k` bananas from that pile. If the pile has less than `k` bananas, she eats all of them instead and will not eat any more bananas during this hour.
Return the minimum integer `k` such that she can eat all the bananas within `h` hours.
### Constraints
- `1 <= piles.length <= 10^4`
- `piles.length <= h <= 10^9`
- `1 <= piles[i] <= 10^9`
### Input Format
First line contains the integer `h`.
Second line contains space-separated integers representing `piles`.
### Output Format
Print the minimum integer speed `k`.
Sample Cases
Example 1Sample Case
Input: 8
3 6 7 11
Output: 4
Example 2Sample Case
Input: 5
30 11 23 4 20
Output: 30
Example 3Sample Case
Input: 8
3
Output: 1
Example 4Sample Case
Input: 8
8
Output: 1
Constraints
Runtime Limit: 2000 ms per test batch
Memory Limit: 256 MB
Standard I/O stream reading
Official submissions are evaluated against hidden test cases on the server to verify time & memory complexity.