Minimum Time to Complete Trips LeetCode solution in JavaScript
1var minimumTime = function (time, totalTrips) {2let low = 1;3let high = Number.MAX_SAFE_INTEGER;4let ans = 0;56while (low <= high) {7let mid = Math.floor(low + (high - low) / 2); // to prevent overflow89if (isPossible(time, mid, totalTrips)) {10ans = mid;11high = mid - 1;12} else {13low = mid + 1;14}15}16return ans;17};1819function isPossible(arr, mid, totalTrips) {20let trips = 0;21for (let i = 0; i < arr.length; i++) {22trips += Math.floor(mid / arr[i]);23}24return trips >= totalTrips;25}