Car capacity trips feasible
Your task
A car drives east along a number line and can carry at most capacity passengers. You are given trips where trips[i] = [num_passengers, from, to] (the car picks up num_passengers at from and drops them at to, with from < to). Return True if it is possible to complete every trip without ever exceeding capacity. There are up to 1000 trips and locations up to 1000; use a difference array over locations and a prefix sweep, not per-trip recomputation.
Examples
car_pooling(trips: list[list[int]], capacity: int) -> boolExample 1
Input
car_pooling([[2, 1, 5], [3, 3, 7]], 4)Output
False