Skip to content

Minimum Time to Complete Trips

MediumBinary Search
Decode it first. Clues, constraints, pattern and plan before any code.

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.

time = [1, 2, 3], total_trips = 5    →  3   (by t = 3: 3 + 1 + 1 = 5 trips)
time = [2],       total_trips = 1    →  2
time = [5, 10, 10], total_trips = 9  →  25

Constraints

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