A car with capacity empty seats only drives east. You are given trips where trips[i] = [numPassengers_i, from_i, to_i]: that many passengers are picked up at location from_i and dropped off at location to_i (locations are kilometers east of the start). Return true if it is possible to pick up and drop off every passenger of every trip, and false otherwise.
A car with capacity empty seats only drives east. You are given trips where trips[i] = [numPassengers_i, from_i, to_i]: that many passengers are picked up at location from_i and dropped off at location to_i (locations are kilometers east of the start). Return true if it is possible to pick up and drop off every passenger of every trip, and false otherwise.
Example 1:
Input: {"trips":[[2,1,5],[3,3,7]],"capacity":4}
Output: false
Constraints:
1≤trips.length≤1000
trips[i].length==3
1≤numPassengersi≤100
0≤fromi<toi≤1000
1≤capacity≤105
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"trips":[[2,1,5],[3,3,7]],"capacity":4}
Instead of tracking every passenger, record only where the load changes: +num where a group boards, -num where it gets off. The car holds 4.
23012345674capacity0passengers in the car
change[] (only non-zero locations)
all zeros
● boards (+)● gets off (-)■ in the car now- - capacity