1
var minEatingSpeed = function (piles, h) {2
/*The range of bananas that Koko can eat is k = 1 to Max(piles)*/4
let endk = Math.max(...piles);6
while (startk <= endk) {7
let midk = Math.floor(startk + (endk - startk) / 2);8
/*midk are the count of bananas that koko decide to eat. 9
So how many hours she will take to finish the piles?*/11
for (let pile of piles) {12
/*pile is the num of bananas in piles*/13
hrs += Math.ceil(pile / midk);16
/*Now if hrs > h she will not be to finish the pile so we have 17
to increase the bananas by moving start.*/20
/*If hrs <= h she will be eating too fast so we can reduce the bananas 21
so she eats slowly. So decrement end.*/