|
8 | 8 |
|
9 | 9 | <p>You are given an integer <code>capacity</code>, which represents the <strong>maximum</strong> number of passengers that can get on each bus.</p>
|
10 | 10 |
|
11 |
| -<p>The passengers will get on the next available bus. You can get on a bus that will depart at <code>x</code> minutes if you arrive at <code>y</code> minutes where <code>y <= x</code>, and the bus is not full. Passengers with the <strong>earliest</strong> arrival times get on the bus first.</p> |
| 11 | +<p>When a passenger arrives, they will wait in line for the next available bus. You can get on a bus that departs at <code>x</code> minutes if you arrive at <code>y</code> minutes where <code>y <= x</code>, and the bus is not full. Passengers with the <strong>earliest</strong> arrival times get on the bus first.</p> |
| 12 | + |
| 13 | +<p>More formally when a bus arrives, either:</p> |
| 14 | + |
| 15 | +<ul> |
| 16 | + <li>If <code>capacity</code> or fewer passengers are waiting for a bus, they will <strong>all</strong> get on the bus, or</li> |
| 17 | + <li>The <code>capacity</code> passengers with the <strong>earliest</strong> arrival times will get on the bus.</li> |
| 18 | +</ul> |
12 | 19 |
|
13 | 20 | <p>Return <em>the latest time you may arrive at the bus station to catch a bus</em>. You <strong>cannot</strong> arrive at the same time as another passenger.</p>
|
14 | 21 |
|
|
20 | 27 | <pre>
|
21 | 28 | <strong>Input:</strong> buses = [10,20], passengers = [2,17,18,19], capacity = 2
|
22 | 29 | <strong>Output:</strong> 16
|
23 |
| -<strong>Explanation:</strong> |
24 |
| -The 1<sup>st</sup> bus departs with the 1<sup>st</sup> passenger. |
25 |
| -The 2<sup>nd</sup> bus departs with you and the 2<sup>nd</sup> passenger. |
26 |
| -Note that you must not arrive at the same time as the passengers, which is why you must arrive before the 2<sup>nd</sup><sup> </sup>passenger to catch the bus.</pre> |
| 30 | +<strong>Explanation:</strong> Suppose you arrive at time 16. |
| 31 | +At time 10, the first bus departs with the 0<sup>th</sup> passenger. |
| 32 | +At time 20, the second bus departs with you and the 1<sup>st</sup> passenger. |
| 33 | +Note that you may not arrive at the same time as another passenger, which is why you must arrive before the 1<sup>st</sup> passenger to catch the bus.</pre> |
27 | 34 |
|
28 | 35 | <p><strong>Example 2:</strong></p>
|
29 | 36 |
|
30 | 37 | <pre>
|
31 | 38 | <strong>Input:</strong> buses = [20,30,10], passengers = [19,13,26,4,25,11,21], capacity = 2
|
32 | 39 | <strong>Output:</strong> 20
|
33 |
| -<strong>Explanation:</strong> |
34 |
| -The 1<sup>st</sup> bus departs with the 4<sup>th</sup> passenger. |
35 |
| -The 2<sup>nd</sup> bus departs with the 6<sup>th</sup> and 2<sup>nd</sup><sup> </sup>passengers. |
36 |
| -The 3<sup>rd</sup> bus departs with the 1<sup>s</sup><sup>t</sup> passenger and you. |
37 |
| -</pre> |
| 40 | +<strong>Explanation:</strong> Suppose you arrive at time 20. |
| 41 | +At time 10, the first bus departs with the 3<sup>rd</sup> passenger. |
| 42 | +At time 20, the second bus departs with the 5<sup>th</sup> and 1<sup>st</sup> passengers. |
| 43 | +At time 30, the third bus departs with the 0<sup>th</sup> passenger and you. |
| 44 | +Notice if you had arrived any later, then the 6<sup>th</sup> passenger would have taken your seat on the third bus.</pre> |
38 | 45 |
|
39 | 46 | <p> </p>
|
40 | 47 | <p><strong>Constraints:</strong></p>
|
|
0 commit comments