Description

Given trips [numPassengers, from, to] and capacity, determine if all passengers can be picked up and dropped off.

Examples

Input:trips = [[2,1,5],[3,3,7]], capacity = 4
Output:false
Explanation:

At location 3, need 5 seats but only have 4.

Input:trips = [[2,1,5],[3,3,7]], capacity = 5
Output:true
Explanation:

Given trips = [[2,1,5],[3,3,7]], capacity = 5, the condition holds: all passengers can be picked up and dropped off.

Input:trips = [[3,2,6],[1,4,8],[2,3,5]], capacity = 4
Output:false
Explanation:

At location 4, there are 3 passengers from trip [3,2,6] and pick up 1 more passenger from trip [1,4,8], totaling 4 passengers (within capacity). However, at location 3, already have 3 passengers from the first trip and need to pick up 2 more from trip [2,3,5], requiring 5 seats but only having 4 capacity.

Constraints

  • 1 ≤ trips.length ≤ 1000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!