496. Minimum Time to Complete Trips

MediumBinary SearchBinary Search on AnswerArray

Given an array where each element is the time a bus takes to complete one trip, and a target total number of trips, return the minimum amount of time required for all buses together to complete at least that many trips. Buses operate independently and in parallel. Input: '[time], totalTrips'.

Input: '[time], totalTrips'.

Output: Integer — the minimum total time.

Examples

Example 1
Input: [1,2,3], 5
Output: 3
Explanation: In 3 units: 3+1+1 = 5 trips.
Example 2
Input: [2], 1
Output: 2
Explanation: One bus, one trip.
Example 3
Input: [1,1,1], 3
Output: 1
Explanation: Three buses, one unit each.

Constraints

Asked by

AmazonGoogleMeta
Solve this problem in the editor →