You are given multiple bus lines. Each line has a sorted list of departure times, in minutes from midnight, ranging from 0 to 1440. You are also given current_time.
Return the next available departure time across all bus lines that is at or after current_time. If current_time is exactly equal to a departure time, that departure is still considered available. If no departure is available at or after current_time on any line, return -1.
Function Signature
def next_departure(lines: list[list[int]], current_time: int) -> int:
Rules
-
lines[i]
is the departure list of line
i
, sorted in non-decreasing order.
-
Return the departure time itself (a minute of the day), not the number of minutes to wait.
-
A departure at exactly
current_time
counts as available.
-
Return
-1
when every departure on every line is earlier than
current_time
.
Constraints
-
1 <= len(lines) <= 100
-
1 <= len(lines[i]) <= 10^5
-
0 <= lines[i][j] <= 1440
-
Each
lines[i]
is sorted in non-decreasing order.
-
0 <= current_time <= 1440
Examples
Input: lines = [[300, 420, 540, 660, 780, 900], [350, 470, 590, 710]], current_time = 500
Output: 540
On the first line the next departure at or after 500 is 540. On the second line it is 590. The earliest across both lines is 540.
Input: lines = [[60, 120, 180], [90, 150, 210]], current_time = 150
Output: 150
The first line's next departure is 180. The second line has a departure at exactly 150, which still counts, so the answer is 150.
Input: lines = [[100, 200], [50]], current_time = 250
Output: -1
Every departure (100, 200 and 50) is before minute 250, so no departure is available on any line.