LeetCode 875. Koko Eating Bananas

Problem Statement


impl Solution {
pub fn min_eating_speed(piles: Vec<i32>, h: i32) -> i32 {
let (mut l, mut r) = (1, *piles.iter().max().unwrap());

while l < r {
let mid = l + (r - l) / 2;
let mut total = 0;
for val in &piles {
total += (*val as f32 / mid as f32).ceil() as i32;
}
if total > h {
l = mid + 1;
} else {
r = mid;
}
}

return l;
}
}