Minimum Time to Complete Trips

You are given an array time where time[i] denotes the time taken by the i^th 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.

Example 1
Inputtime = [1,2,3], totalTrips = 5
Output3
At time t = 3, the buses complete [3, 1, 1] trips for a total of 5 trips, so 3 is the minimum time needed.
Example 2
Inputtime = [2], totalTrips = 1
Output2
There is only one bus, and it completes its first trip at t = 2, so the minimum time needed is 2.

Constraints

  • 1 <= time.length <= 10^5
  • 1 <= time[i], totalTrips <= 10^7

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate