departures[i] is when bus i departs. Passengers come to the stop: arrivals[j] is when passenger j arrives. All departure times are distinct, and so are all arrival times. Each bus holds seats people. The arrays are not necessarily sorted.
Passengers queue in order of arrival. When a bus leaves at time t, the people at the front of the queue who came no later than t board it until the seats run out. Everyone else waits for the next bus.
You also want to catch some bus, but arrive as late as possible. You may not arrive at the same moment as another passenger. Return the latest arrival time that still gets you a seat.departures=[15, 30], arrivals=[3, 14, 26, 29, 30], seats=2 → 28
At 15 the passengers who came at 3 and 14 leave. By 30 the ones from 26, 29 and 30 are waiting, with two seats. If you come at 28, you are second in line, after 26 and ahead of 29, and you get a seat.
departures=[40, 10], arrivals=[5, 9], seats=3 → 40
The last bus leaves at 40 with free seats, so you can arrive right at its departure.
departures=[20], arrivals=[17, 18, 19, 20], seats=2 → 16
Only the first two, 17 and 18, get on. You must come before 18 to be among them; 17 is taken, so the answer is 16.
departures are distinct, and so are the values in arrivalsdepartures=[15, 30], arrivals=[3, 14, 26, 29, 30], seats=2
28
Run checks the first 3 tests in your browser. Submit checks all 95 tests on the server, hidden ones included.