We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d68739b commit 5d9e24bCopy full SHA for 5d9e24b
13 June Koko Eating Bananas
@@ -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