← Questions

Minimum buses to run a timetable

0
SnowflakeCodingLast asked Sep 2026

A bus depot has a timetable of trips, each with a departure time and an arrival time. A bus can take a new trip once it has arrived from its previous one. Return the fewest buses needed to run every trip (a meeting-rooms style problem).

Follow-up: each trip now also has a departure station and an arrival station, and a bus can only take a trip that leaves from the station where it currently is. Find the fewest buses again. Aim for a heap-based solution rather than scanning every bus.

Write and test your solution herePython in your browser, the question's tests level by level, saved for you.Sign in to start coding