Fewest Shuttle Lines to Ride Between Two ByteDance Campus Stops

Last updated: November 29, 2026

Quick Overview

Each shuttle line loops through a list of stops across ByteDance's offices; given all lines, a source stop and a target stop, return the minimum number of distinct lines an employee must board, or -1 if impossible.

ByteDance
Coding & Algorithms
Software Engineer
ByteDance
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Each shuttle line loops through a list of stops across ByteDance's offices; given all lines, a source stop and a target stop, return the minimum number of distinct lines an employee must board, or -1 if impossible.

Campus shuttles connecting ByteDance office parks give a friendly framing to a graph-modeling problem seen in ByteDance onsites. The interviewer watches whether you realize the state is a line, not a stop, and whether you avoid the quadratic blow-up of connecting every pair of stops.

What the Interviewer Expects
  • Recognize the cost is per line boarded, not per stop
  • Build a stop-to-lines index
  • BFS where each line is expanded at most once
  • Return 0 when source equals target
  • Explain O(total stops) time
Key Topics to Cover
BFS
graph modeling
hash maps
shortest path
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Lines also have travel times: minimize total time with at most k transfers.
  • How would you return the actual sequence of lines?
  • Routes change during the day: how would you update the index cheaply?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: routes, a list of lists of stop IDs (a line serves all its stops in both directions), plus source and target. Output: minimum lines boarded. If source equals target the answer is 0 without boar...

High-Level Design

Think of a bipartite graph between stops and lines. BFS from the source stop: from a stop, board every unused line serving it; from a line, reach every stop on it with one more ride. Marking lines as ...


Submit Your Answer
Markdown supported