Minimum Bus Fleet
Asked at Snowflake
Reported by the problem's creator, not verified
A bus company operates a list of trips, where each trip is [departure, arrival, origin, destination]: a bus leaves station origin at time departure and reaches station destination at time arrival.
Buses may start the day at any station. A bus can only change stations by driving a trip, so after a trip it waits at that trip's destination. A bus that arrives at a station at time t can start a trip from that station departing at time t or later. Every trip is driven exactly once, by one bus.
Examples
Example 1
Input: trips =
[[0,4,1,2],[4,7,2,1],[4,6,1,2]]Output:
2Explanation: One bus drives the first trip, waits at station 2, and departs on the second trip at time 4. No bus is at station 1 when the third trip departs at time 4, so a second bus drives it.
Example 2
Input: trips =
[[0,2,1,2],[3,5,1,2]]Output:
2Explanation: Both trips leave station 1. After the first trip the bus sits at station 2, where no trip departs, so the second trip needs its own bus.