Skip to content

Commit

Permalink
Create 875. Koko Eating Bananas.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
KashishJuneja101003 authored Jan 30, 2025
1 parent 4d69a72 commit bfeb94c
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions 875. Koko Eating Bananas.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Solution {
public:
long long eatingTime(vector<int>& piles, int k){
long long time = 0;

for(int i:piles){
time += (i+k-1LL)/k;
}

return time;
}

int minEatingSpeed(vector<int>& piles, int h) {
int n = piles.size();
int start = 1, end = *max_element(piles.begin(), piles.end());
int minSpeed;

while(start <= end){
int mid = start + (end-start)/2;

if(eatingTime(piles, mid) <= h){
minSpeed = mid;
end = mid-1;
} else{
start = mid+1;
}
}

return minSpeed;
}
};

0 comments on commit bfeb94c

Please sign in to comment.