In an example where Koko aims to minimize the time required to finish all the bananas, and the piles vary in size, you can determine the maximum size among the piles (let's denote it as maxSize ). Next, perform a binary search ranging from 1 to maxSize to find the minimum time needed for Koko to consume the bananas. For each time calculation, you compute the total time for all piles using the formula (pile[i] - 1) / mid + 1. If the resulting time exceeds H , continue the binary search; otherwise, terminate the search. Thus, the pseudo code is as follows: function minEatingSpeed(piles, H) { let left = 1, right = Math.max(...piles) while(left < right) { let mid = left + (right - left) / 2 if(piles.reduce((a, b) => a + Math.ceil(b / mid), 0) > H) { left = mid + 1 } else { right = mid } } return left }