Skip to content

Commit 59c49a0

Browse files
authored
Create 13 June Koko Eating Bananas (#815)
2 parents d68739b + 5d9e24b commit 59c49a0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

13 June Koko Eating Bananas

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
int kokoEat(vector<int>& arr, int k) {
4+
// Code here
5+
int low = 1;
6+
int high = *max_element(arr.begin(), arr.end());
7+
int ans = INT_MAX;
8+
while(low <= high){
9+
int mid = low + (high - low)/2;
10+
int curr = 0;
11+
for(int i = 0; i < arr.size(); i++){
12+
curr += ceil((double)arr[i]/mid);
13+
}
14+
if(curr <= k){
15+
ans = min(ans, mid);
16+
high = mid - 1;
17+
}else{
18+
low = mid + 1;
19+
}
20+
}
21+
return ans == INT_MAX ? -1 : ans;
22+
}
23+
};

0 commit comments

Comments
 (0)