`{"id":"1f786694-bdf4-4629-ad10-fcac2bb52ab0","name":"Koko Eating Bananas","description":"1. Koko loves to eat bananas. There are n piles of bananas, the ith pile has piles[i] bananas. The guards have gone and will come back in h hours.\r\n2. Koko can decide her bananas-per-hour eating speed of k. Each hour, she chooses some pile of bananas and eats k bananas from that pile. If the pile has less than k bananas, she eats all of them instead and will not eat any more bananas during this hour.\r\n3. Koko likes to eat slowly but still wants to finish eating all the bananas before the guards return.\r\n4. Return the minimum integer k such that she can eat all the bananas within h hours.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= piles.length &lt;= 10^4\r\npiles.length &lt;= h &lt;= 10^9\r\n1 &lt;= piles[i] &lt;= 10^9","sampleCode":{"cpp":{"code":"#include <iostream>\r\n#include <vector>\r\n\r\nusing namespace std;\r\n\r\nint minEatingSpeed(vector<int> &arr){\r\n // write your code here\r\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n public static int minEatingSpeed(int[]piles,int h) {\r\n //write your code here\r\n }\r\n\r\n public static void main(String[]args) {\r\n Scanner scn = new Scanner(System.in);\r\n //input work\r\n int n = scn.nextInt();\r\n int[]piles = new int[n];\r\n\r\n for(int i=0 ; i < n ; i++) {\r\n piles[i] = scn.nextInt();\r\n }\r\n\r\n int h = scn.nextInt();\r\n\r\n int speed = minEatingSpeed(piles,h);\r\n System.out.println(speed);\r\n }\r\n}"},"python":{"code":"def main():\r\n pass\r\nif_name_=='__main__':\r\n main()"}},"points":10,"difficulty":"medium","sampleInput":"4\r\n3 6 7 11\r\n8","sampleOutput":"4","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"c8164bee-53e7-4501-a128-7bd194b463a7","name":"Koko Eating Bananas","slug":"koko-eating-bananas","type":1}],"next":{"id":"5355eb3b-4d7f-448d-acdc-e64f87368617","name":"Koko Eating Bananas","type":3,"slug":"koko-eating-bananas"},"prev":{"id":"c7b1a486-0e45-4a85-8def-9afb9303f79b","name":"Find Rotation Count MCQ","type":0,"slug":"find-rotation-count-mcq"}}}`

# Koko Eating Bananas

1. Koko loves to eat bananas. There are n piles of bananas, the ith pile has piles[i] bananas. The guards have gone and will come back in h hours. 2. Koko can decide her bananas-per-hour eating speed of k. Each hour, she chooses some pile of bananas and eats k bananas from that pile. If the pile has less than k bananas, she eats all of them instead and will not eat any more bananas during this hour. 3. Koko likes to eat slowly but still wants to finish eating all the bananas before the guards return. 4. Return the minimum integer k such that she can eat all the bananas within h hours.

`{"id":"1f786694-bdf4-4629-ad10-fcac2bb52ab0","name":"Koko Eating Bananas","description":"1. Koko loves to eat bananas. There are n piles of bananas, the ith pile has piles[i] bananas. The guards have gone and will come back in h hours.\r\n2. Koko can decide her bananas-per-hour eating speed of k. Each hour, she chooses some pile of bananas and eats k bananas from that pile. If the pile has less than k bananas, she eats all of them instead and will not eat any more bananas during this hour.\r\n3. Koko likes to eat slowly but still wants to finish eating all the bananas before the guards return.\r\n4. Return the minimum integer k such that she can eat all the bananas within h hours.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= piles.length &lt;= 10^4\r\npiles.length &lt;= h &lt;= 10^9\r\n1 &lt;= piles[i] &lt;= 10^9","sampleCode":{"cpp":{"code":"#include <iostream>\r\n#include <vector>\r\n\r\nusing namespace std;\r\n\r\nint minEatingSpeed(vector<int> &arr){\r\n // write your code here\r\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n public static int minEatingSpeed(int[]piles,int h) {\r\n //write your code here\r\n }\r\n\r\n public static void main(String[]args) {\r\n Scanner scn = new Scanner(System.in);\r\n //input work\r\n int n = scn.nextInt();\r\n int[]piles = new int[n];\r\n\r\n for(int i=0 ; i < n ; i++) {\r\n piles[i] = scn.nextInt();\r\n }\r\n\r\n int h = scn.nextInt();\r\n\r\n int speed = minEatingSpeed(piles,h);\r\n System.out.println(speed);\r\n }\r\n}"},"python":{"code":"def main():\r\n pass\r\nif_name_=='__main__':\r\n main()"}},"points":10,"difficulty":"medium","sampleInput":"4\r\n3 6 7 11\r\n8","sampleOutput":"4","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"c8164bee-53e7-4501-a128-7bd194b463a7","name":"Koko Eating Bananas","slug":"koko-eating-bananas","type":1}],"next":{"id":"5355eb3b-4d7f-448d-acdc-e64f87368617","name":"Koko Eating Bananas","type":3,"slug":"koko-eating-bananas"},"prev":{"id":"c7b1a486-0e45-4a85-8def-9afb9303f79b","name":"Find Rotation Count MCQ","type":0,"slug":"find-rotation-count-mcq"}}}`

Editor

# Koko Eating Bananas

medium

1. Koko loves to eat bananas. There are n piles of bananas, the ith pile has piles[i] bananas. The guards have gone and will come back in h hours. 2. Koko can decide her bananas-per-hour eating speed of k. Each hour, she chooses some pile of bananas and eats k bananas from that pile. If the pile has less than k bananas, she eats all of them instead and will not eat any more bananas during this hour. 3. Koko likes to eat slowly but still wants to finish eating all the bananas before the guards return. 4. Return the minimum integer k such that she can eat all the bananas within h hours.

## Constraints

1 <= piles.length <= 10^4 piles.length <= h <= 10^9 1 <= piles[i] <= 10^9

## Format

### Input

Input is managed for you

### Output

Output is managed for you

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}4 3 6 7 11 8```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}4`

Discussions

Show Discussion

Related Resources