Skip to content
Decoder

Minimum Time to Complete Trips

Medium

Problem

Bus i takes time[i] minutes to complete one trip, and every bus can start its next trip immediately. All buses run at the same time, independently. Return the minimum time needed for the buses to complete at least total_trips trips in total.

Example 1

Input
time = [1, 2, 3], total_trips = 5
Output
3
Why
by t = 3: 3 + 1 + 1 = 5 trips

Example 2

Input
time = [2], total_trips = 1
Output
2

Example 3

Input
time = [5, 10, 10], total_trips = 9
Output
25

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.