#107

Trip Validity with Max Passengers

MEDIUMSweep LinePYTHON

Problem Description

A capacity planning service for a ride-sharing platform ingests trip event streams and must validate in real time whether concurrent bookings stay within vehicle capacity limits. Given a list of trip segments, determine whether the schedule is valid. **Input:** A list `trips` of tuples `(start, end, passengers)` and an integer `max_pass` representing the vehicle capacity. **Output:** `True` if at no point in time do concurrent passengers exceed `max_pass`, `False` otherwise. **Key Rules:** - A passenger is aboard during the interval `[start, end)` (end is exclusive). - Multiple trips can overlap in time; their passenger counts are summed. - An empty trip list is always valid.

Topics

arraysortingsweep lineinterval processing

Asked at Companies

meta

Solve This Problem

Sign up to access the interactive code editor, run test cases, view the editorial, and get AI-powered feedback on your solution.

Start Solving →