Skip to content

Commit

Permalink
Created 875-Koko-Eating-Bananas
Browse files Browse the repository at this point in the history
  • Loading branch information
loczek committed Jul 8, 2022
1 parent f1495f0 commit c525834
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions typescript/875-Koko-Eating-Bananas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function minEatingSpeed(piles: number[], h: number): number {
let l = 1;
let r = Math.max(...piles);
let res = r;

while (l <= r) {
let k = Math.floor((l + r) / 2);
let hours = 0;
for (const p of piles) {
hours += Math.ceil(p / k);
}
if (hours <= h) {
res = Math.min(res, k);
r = k - 1;
} else {
l = k + 1;
}
}

return res;
}

0 comments on commit c525834

Please sign in to comment.