1094. Car Pooling

Practice Car Pooling for free on NudgeCode: Medium, Heap pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

A car with capacity empty seats drives in one direction only (east). Each trip trips[i] = [numPassengers, from, to] picks up numPassengers people at kilometre from and drops them off at kilometre to. Passengers leave before new ones board at the same point.

Return true if the car can serve every trip without ever carrying more than capacity passengers, and false otherwise.

Example

trips = [[2,1,5],[3,3,7]], capacity = 4  ->  false
trips = [[2,1,5],[3,3,7]], capacity = 5  ->  true

Constraints