Pinterest·Machine Learning Engineer·Technical Phone Screen
- You have a list of bus routes where each route is a loop of stops. Given a source stop and a target stop, return the minimum number of buses needed to travel from source to target, or -1 if it's not possible.
- Follow-up: given the same bus routes setup, now support repeated queries asking for the minimum number of buses between any two arbitrary stops. How do you handle this efficiently?
“Went with BFS treating each route as a node rather than each stop.”