Problem
A car with capacity empty seats drives east only (it never turns around). trips[i] = [num_passengers, from, to] means a group of num_passengers gets in at kilometer from and gets out at kilometer to.
Return true if the car can complete every trip without ever exceeding `capacity`, and false otherwise. Passengers getting out at a kilometer free their seats before anyone gets in there.
Example 1
- Input
- trips = [[2, 1, 5], [3, 3, 7]], capacity = 4
- Output
- false
- Why
- 5 people between km 3 and 5
Example 2
- Input
- trips = [[2, 1, 5], [3, 3, 7]], capacity = 5
- Output
- true
Example 3
- Input
- trips = [[2, 1, 5], [3, 5, 7]], capacity = 3
- Output
- true
- Why
- the first group leaves at 5
Constraints
1 <= trips.length <= 10001 <= num_passengers <= 1000 <= from < to <= 10001 <= capacity <= 10^5