Fewest Shuttle Rides Between Two Stops on an Amazon Campus
Last updated: November 29, 2026
Quick Overview
Each campus shuttle loops forever through a fixed list of stops. Given all shuttle routes, a source stop and a destination stop, return the minimum number of shuttles you must ride to get from source to destination, or -1 if impossible.
Amazon
November 29, 20260
0
0 solved
Each campus shuttle loops forever through a fixed list of stops. Given all shuttle routes, a source stop and a destination stop, return the minimum number of shuttles you must ride to get from source to destination, or -1 if impossible.
An Amazon onsite hard BFS question about getting between buildings on a large corporate campus. The interviewer checks that you BFS over routes (shuttles) rather than stops, since the cost is the number of boardings, and that you mark routes and stops visited to keep the search linear.
What the Interviewer Expects
- Notice the cost is shuttles boarded, not stops passed
- Build a map from stop to the routes serving it
- BFS over routes, level by level
- Mark both routes and stops visited to avoid rescanning
- Return 0 when source equals destination
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if each ride also has a travel time and you minimize time?
- How would you return the actual sequence of shuttles?
- What if some shuttles only run in one direction during certain hours?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: routes, list of stop-ID lists (each route visits its stops cyclically); source, target stop IDs. Output: minimum number of routes boarded, or -1. Up to 500 routes and 1e5 total stops....
High-Level Design
Build stop_to_routes. Start by boarding every route that serves the source, which costs 1. BFS over routes: when processing a route at distance d, every stop on it is reachable with d boardings; if ...