Imagine you're managing a bus terminal where multiple buses operate on different schedules. Each bus has its own trip duration, and they all work independently to serve passengers.
You are given an array time where time[i] represents the time it takes for the i-th bus to complete one round trip. Each bus can immediately start its next trip after finishing the current one, operating continuously without any downtime.
Your goal is to find the minimum time required for all buses combined to complete at least totalTrips trips. Think of it as finding the optimal scheduling point where your bus fleet achieves the required service level.
Example: If you have buses with trip times [1, 2, 3] and need 5 total trips, you need to find when the combined trips from all buses first reaches or exceeds 5.
Input & Output
Visualization
Time & Space Complexity
T is the minimum time needed (could be very large), n is number of buses
Only using constant extra space for calculations
Constraints
- 1 โค time.length โค 105
- 1 โค time[i], totalTrips โค 107
- All buses operate independently and continuously
- Answer will fit in a 64-bit signed integer