Code Room
CodingMediumcod-g664
Subject Sweep lineLevel Mid–Senior~18 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

A car drives east along a number line and can carry at most `capacity` passengers. You are given `trips` where trips[i] = [num_passengers, from, to] (the car picks up num_passengers at `from` and drops them at `to`, with from < to). Return True if it is possible to complete every trip without ever exceeding capacity. There are up to 1000 trips and locations up to 1000; use a difference array over locations and a prefix sweep, not per-trip recomputation.

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.