2332. The Latest Time to Catch a Bus
Содержание
class Solution:
def latestTimeCatchTheBus(
self, buses: List[int], passengers: List[int], capacity: int
) -> int:
buses.sort()
passengers.sort()
j = 0
for t in buses:
c = capacity
while c and j < len(passengers) and passengers[j] <= t:
c, j = c - 1, j + 1
j -= 1
res = buses[-1] if c else passengers[j]
while ~j and passengers[j] == res:
res, j = res - 1, j - 1
return res