15% off all plans & roadmaps Use code
See plansProblem editorial
Implement Solution.carPooling to determine whether one vehicle can complete every requested trip while respecting its passenger capacity. The vehicle travels only east, so locations are ordered along a single route.
Car Pooling is a Greedy Patterns problem, in the Line Sweep subpattern. The pattern covers interval scheduling, jump games, stock trading, and task scheduling
The reference solution runs in O(trips.length + 1000) time and O(1000) space.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Car Pooling is a Greedy Patterns problem, in the Line Sweep subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.