(video 52 ) Binary Search Leetcode 2064. Minimized Maximum of Products Distributed to Any Store


class Solution {
    public boolean isPossible(int[] arr , int n , int val)
    {
        int sum=0;
        for(int i=0;i<arr.length;i++)
        {
            int c=arr[i]/val;
            if(arr[i]%val != 0 )
                c++;

            n-=c;
            // sum+=c;   can use the commented or yhe line  befor them 
            if(n<0)
            return false;
        }
        // if(sum<=n)
        // return true;
        return true;
    }
    public int minimizedMaximum(int n, int[] quantities) {
        
        int l=1;
        int r= 100000;
        while(l<=r)
        {
            int mid = l + (r-l)/2;

            if(isPossible(quantities,n,mid))
            r = mid -1;
            else
            l = mid + 1 ;
        }
                return l;
    }
}