Spend the flexible driver last
transcript
Two drivers are free. One is free at minute zero. One is free at minute five. Two riders want a ride.
Rider A pays nine and leaves at ten. Rider B pays eight and leaves at three. Each driver serves one rider.
Rider A takes the earliest driver. Rider B now finds nobody. The total is only nine. The latest fitting driver gives seventeen.
Drivers are free at zero and five. Rider B can only use the driver at zero. Rider A can use either driver. So A should take the driver at five.
An early driver fits any rider. A late driver fits few riders. Spend the flexible one last.
Take the highest fare first. Give it the latest driver who fits. Never the earliest by habit.
A city has many riders. And many drivers. Nested loops are too slow there.
Use two drivers. Make one rider leave early. The early driver must stay free.
Latest driver who fits. Full breakdown in the lecture.