Class Solution
java.lang.Object
g2101_2200.s2187_minimum_time_to_complete_trips.Solution
2187 - Minimum Time to Complete Trips.<p>Medium</p>
<p>You are given an array <code>time</code> where <code>time[i]</code> denotes the time taken by the <code>i<sup>th</sup></code> bus to complete <strong>one trip</strong>.</p>
<p>Each bus can make multiple trips <strong>successively</strong>; that is, the next trip can start <strong>immediately after</strong> completing the current trip. Also, each bus operates <strong>independently</strong>; that is, the trips of one bus do not influence the trips of any other bus.</p>
<p>You are also given an integer <code>totalTrips</code>, which denotes the number of trips all buses should make <strong>in total</strong>. Return <em>the <strong>minimum time</strong> required for all buses to complete <strong>at least</strong></em> <code>totalTrips</code> <em>trips</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> time = [1,2,3], totalTrips = 5</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong></p>
<ul>
<li>At time t = 1, the number of trips completed by each bus are [1,0,0].</li>
</ul>
<p>The total number of trips completed is 1 + 0 + 0 = 1.</p>
<ul>
<li>At time t = 2, the number of trips completed by each bus are [2,1,0].</li>
</ul>
<p>The total number of trips completed is 2 + 1 + 0 = 3.</p>
<ul>
<li>At time t = 3, the number of trips completed by each bus are [3,1,1].</li>
</ul>
<p>The total number of trips completed is 3 + 1 + 1 = 5.</p>
<p>So the minimum time needed for all buses to complete at least 5 trips is 3.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> time = [2], totalTrips = 1</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong></p>
<p>There is only one bus, and it will complete its first trip at t = 2.</p>
<p>So the minimum time needed to complete 1 trip is 2.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= time.length <= 10<sup>5</sup></code></li>
<li><code>1 <= time[i], totalTrips <= 10<sup>7</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minimumTime
public long minimumTime(int[] time, int totalTrips)
-