You are given an array time where time[i] denotes the time taken by the ith bus to complete one trip.

Each bus can make multiple trips successively; that is, the next trip can start immediately after completing the current trip. Also, each bus operates independently; that is, the trips of one bus do not influence the trips of any other bus.

You are also given an integer totalTrips, which denotes the number of trips all buses should make in total. Return the minimum time required for all buses to complete at least totalTrips trips.

&nbsp;
Example 1:

Input: time = [1,2,3], totalTrips = 5
Output: 3
Explanation:
- At time t = 1, the number of trips completed by each bus are [1,0,0]. 
  The total number of trips completed is 1 + 0 + 0 = 1.
- At time t = 2, the number of trips completed by each bus are [2,1,0]. 
  The total number of trips completed is 2 + 1 + 0 = 3.
- At time t = 3, the number of trips completed by each bus are [3,1,1]. 
  The total number of trips completed is 3 + 1 + 1 = 5.
So the minimum time needed for all buses to complete at least 5 trips is 3.


Example 2:

Input: time = [2], totalTrips = 1
Output: 2
Explanation:
There is only one bus, and it will complete its first trip at t = 2.
So the minimum time needed to complete 1 trip is 2.


&nbsp;
Constraints:


	1 &lt;= time.length &lt;= 105
	1 &lt;= time[i], totalTrips &lt;= 107


class Solution(object):
    def minimumTime(self, time, totalTrips):
        anstillnow=-1;
        left=1;
        right= 100000000000001;
        
        while(left<=right):
            mid= left+ (right-left)/2      #find mid point like this to avoid overflow
            
            curr_trips=0;
            
            for t in time:
                curr_trips+= mid/t
            
            if(curr_trips>=totalTrips):
                anstillnow=mid
                right=mid-1
            
            else:
                left=mid+1

        return anstillnow
class Solution {
    public long minimumTime(int[] time, int totalTrips) {
        long anstillnow=-1;
        
        long left=1, right= 100000000000001L;
        
        while(left<=right){
            long mid= left+ (right-left)/2;  //find mid point like this to avoid overflow
            long curr_trips=0;
            for(int t: time){
                curr_trips+= mid/t;
            }
            
            if(curr_trips>=totalTrips){
                anstillnow=mid;
                right=mid-1;
            }
            
            else{
                left=mid+1;
            }
        }
        
        return anstillnow;        
    }
}
class Solution {
public:
    long long minimumTime(vector<int>& time, int totalTrips) {
        long long anstillnow=-1;

        long long left=1, right= 100000000000001; //can also write this as 1+1e14

        while(left<=right){
            long long mid= left+ (right-left)/2; // find mid point like this to avoid overflow
            long long curr_trips=0;
            for(int t: time){
                curr_trips+= mid/t;
            }

            if(curr_trips>=totalTrips){
                anstillnow=mid;
                right=mid-1;
            }

            else{
                left=mid+1;
            }
        }

        return anstillnow;
    }
};
var minimumTime = function(time, totalTrips) {
    let low = 1;
    let high = Number.MAX_SAFE_INTEGER;
    let ans = 0;
    
    while(low <= high) {
        let mid = Math.floor(low + (high - low) / 2); // to prevent overflow
        
        if(isPossible(time, mid, totalTrips)) {
            ans = mid
            high = mid - 1;
        } else {
            low = mid + 1;
        }
    }
    return ans;
};

function isPossible(arr, mid, totalTrips) {
    let trips = 0;
    for (let i = 0; i < arr.length; i++) {
      trips += Math.floor(mid / arr[i]);
    }
    return trips >= totalTrips;
}
Minimum Time to Complete Trips