Find minimum shuttle transfers
PinterestSoftware Engineer · Online AssessmentLast updated
Find minimum shuttle transfers evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
You are given a collection of shuttle loops, each represented by a list of stop IDs that the loop visits in perpetuity. You may board a shuttle at any stop it serves and remain on it until any later stop on the same loop. Transferring from one shuttle loop to another counts as boarding a new shuttle. Given a source stop s and a target stop t, determine the minimum number of shuttles you must board to travel from s to t; return -1 if it is impossible. Describe the data structures you would use, outline the algorithm step by step, and analyze time and space complexity for inputs with up to 100,000 total stops across all loops. Discuss edge cases such as s == t, isolated loops, and multiple loops sharing the same stop. Follow-ups: how would you output an actual sequence of shuttles taken; how would you handle weighted transfer penalties or restricted operating hours; how can you reduce memory and avoid building an explicit route-to-route graph when the number of loops is very large?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.