Skip to main content

1094. Car Pooling

Python

class Solution:
def carPooling(self, trips: List[List[int]], capacity: int) -> bool:
start = min([trip[1] for trip in trips])
end = max([trip[2] for trip in trips])

counter = [0 for i in range(start, end+1)]

for trip in trips:
passengers, fromP, toP = trip
for point in range(fromP, toP):
counter[point-start] += passengers

return not any(took > capacity for took in counter)