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.

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.

Koko likes to eat slowly but still wants to finish eating all the bananas before the guards return.

Return the minimum integer k such that she can eat all the bananas within h hours.

&nbsp;
Example 1:

Input: piles = [3,6,7,11], h = 8
Output: 4


Example 2:

Input: piles = [30,11,23,4,20], h = 5
Output: 30


Example 3:

Input: piles = [30,11,23,4,20], h = 6
Output: 23


&nbsp;
Constraints:


	1 &lt;= piles.length &lt;= 104
	piles.length &lt;= h &lt;= 109
	1 &lt;= piles[i] &lt;= 109


class Solution:
    def minEatingSpeed(self, piles: List[int], h: int) -> int:
        def check(x):
            return sum(ceil(ele/x) for ele in piles) <= h

        l = 1
        r = max(piles)
        while l < r:
            mid = (l+r) >> 1
            if not check(mid):
                l=mid+1
            else:
                r=mid
        return l
class Solution {
    public int minEatingSpeed(int[] piles, int h) {
        int max=0;
        int ans=0;
        for(int i=0;i<piles.length;i++)
        {
            max=Math.max(piles[i],max);
        }
        if(piles.length==h)
            return max;
        int left=1;
        int right=max;
        while(left<=right)
        {
            int mid=left+(right-left)/2;
            double num=0;
            int time=0;
            for(int i=0;i<piles.length;i++)
            {
                num=(double)piles[i]/(mid);
                if(num>piles[i]/mid)
                    time+=num+1;
                else
                    time+=num;
            }
            if(time<=h)
            {
                ans=mid;
                right=mid-1;
            }
            else
                left=mid+1;
        }
        return ans;
    }
}
class Solution {
public:
    int minEatingSpeed(vector<int>& piles, int h) {
        
        int mx=1000000001;
        
        
        int st=1;
        
        
        while(mx>st)
        {
            
            int k = ((mx+st)/2);
            
            int sum=0;
            
            for(int i =0 ;i < piles.size() ; i++)
            {
                sum+=ceil(1.0 *piles[i]/k);
            }
            
            if(sum>h)
            {
                st=k+1;
            }
            else
            {
                mx=k;
            }
            
        }
        
        
        return st;
        
        
        
    }
};
var minEatingSpeed = function(piles, h) {
    /*The range of bananas that Koko can eat is k = 1 to Max(piles)*/
    let startk = 1;
    let endk = Math.max(...piles);
    
    while(startk <= endk){
        let midk = Math.floor(startk + (endk - startk)/2);
        /*midk are the count of bananas that koko decide to eat. 
        So how many hours she will take to finish the piles?*/
        let hrs = 0;
        for(let pile of piles){
            /*pile is the num of bananas in piles*/
            hrs += Math.ceil(pile/midk);
        }
        if(hrs > h){
            /*Now if hrs > h she will not be to finish the pile so we have 
            to increase the bananas by moving start.*/
            startk = midk + 1;
        }else{
            /*If hrs <= h she will be eating too fast so we can reduce the bananas 
            so she eats slowly. So decrement end.*/
            endk = midk - 1;
        }
    }
    return startk;
};
Koko Eating Bananas