Skip to content

Practice Car Pooling

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1094
LeetCode Problem

Car Pooling

Problem Statement

A vehicle with capacity seats travels only east. Each trip [numPassengers, from, to] picks up that many passengers at from and drops them at to, with locations measured from the starting point. Drop-offs occur before pickups at the same location. Return whether all trips can be served without the number of onboard passengers ever exceeding capacity.

Source: Car Pooling on LeetCode. Use the original task for its coding environment and submissions.

Examples

# 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

Constraints

1 <= trips.length <= 1000
trips[i].length == 3
1 <= numPassengersi <= 100
0 <= fromi < toi <= 1000
1 <= capacity <= 10^5

Related LeetCode Problems

Practice more problems similar to Car Pooling.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.