Code RoomShuttle capacity feasibility
MediumPrep Room Coding #1418

Shuttle capacity feasibility

CodingAlgorithms & data structuresMid–Senior~25 min

A shuttle with a fixed passenger capacity drives strictly east along a number line, never reversing. You are given trips, each [numPassengers, start, end], meaning that many passengers board at location start and alight at location end (they occupy the vehicle on [start, end)). Return True if it is possible to serve every trip without ever exceeding capacity, otherwise False.

Implement
car_pooling(trips: list[list[int]], capacity: int) → bool
Examples
in[[[2,1,5],[3,3,7]],4]outfalse
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 25 min
InputExpectedGot
[[[2,1,5],[3,3,7]],4]falsenot run yetsample