#1094

Car Pooling

specialist · 770 · lc medium +31 · verified · 56.2% accepted · 4,817 likes · top 50%

Description

A car with capacity seats only travels east. You are given trips[i] = [numPassengersi, fromi, toi], meaning numPassengersi passengers board at fromi and exit at toi (both in km east of the starting point).

Return true if all passengers can be picked up and dropped off without the car ever exceeding capacity, or false otherwise.

Example 1:

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

Example 2:

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

Code

1
2
3