Intervals - Car Pooling
Consider the following Python code implementing the optimal car pooling solution. What is the return value when called with trips = [[2,1,5],[3,3,7]] and capacity = 4?
def carPooling(trips, capacity):
max_location = 0
for _, start, end in trips:
max_location = max(max_location, end)
diff = [0] * (max_location + 1)
for num, start, end in trips:
diff[start] += num
diff[end] -= num
current_passengers = 0
for i in range(max_location + 1):
current_passengers += diff[i]
if current_passengers > capacity:
return false
return true
print(carPooling([[2,1,5],[3,3,7]], 4))
