Problem · Array
Car Pooling Capacity Check
Learn this problemProblem statement
A vehicle has integer capacity. Each row [passengers, start, end] in trips means that many passengers ride on the half-open interval [start, end).
Return true if every trip can be completed without the number of passengers aboard exceeding capacity; otherwise return false. Drop-offs at a location happen before pickups at that same location.
Function
canCarryAll(capacity: int, trips: int[][]) → booleanExamples
Example 1
capacity = 4trips = [[2,1,5],[3,3,7]]return = falseFive passengers would be aboard between locations 3 and 5.
Example 2
capacity = 5trips = [[2,1,5],[3,3,7]]return = trueThe maximum load is exactly five.
Constraints
1 <= capacity <= 10^90 <= trips.length <= 200000- Each trip has
1 <= passengers <= 10^9and0 <= start < end <= 10^9.