← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Uber SWE phone screen that was basically just LC 815 verbatim. The problem itself isn't hard once you know the route-as-node trick, but if you've never seen it before you're probably building a stop-level BFS and wondering why it's slow.

Questions Asked (1)

Q1

Given a list of bus routes (each route loops through its stops forever), find the minimum number of buses you need to ride to get from a source stop to a target stop. Return -1 if it's unreachable.

Algorithms & Data Structures
Author's notes

The key thing nobody tells you upfront: BFS over routes, not stops.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a graph where each bus route is a node, and edges exist between routes that share a stop. Use BFS from all routes containing the source stop to find the minimum number of routes (buses) to reach any route containing the target stop. Handle edge cases like source equals target (0 buses) and unreachable target (-1).

Pro tip: Clarify that you're counting buses (routes), not stops, and that you can transfer at any common stop. Mention that BFS is optimal because each bus ride adds uniform cost, and precomputing stop-to-routes mapping avoids redundant checks.

1. Clarify and define the graph

Confirm that each bus route is a node, and two routes are connected if they share at least one stop. The goal is to find the shortest path in terms of number of routes from any route containing the source to any route containing the target.

2. Build stop-to-routes mapping

Create a hash map from each stop to the list of routes that include it. This allows efficient lookup of which routes serve a given stop.

3. Initialize BFS with source routes

Find all routes that contain the source stop and enqueue them with distance 1 (since taking one bus). If the source stop is the target, return 0 immediately.

4. BFS traversal

While the queue is not empty, pop a route, and for each stop on that route, find all other routes serving that stop. If a route hasn't been visited, mark it visited and enqueue with distance+1. If any of these routes contains the target stop, return the distance.

5. Return result

If BFS completes without reaching a route containing the target, return -1. Otherwise, the first time we encounter a route with the target, return the current distance.

Key Points to Mention

  • Graph modeling: routes as nodes, edges based on shared stops.
  • BFS guarantees minimum number of buses because each edge represents one bus ride.
  • Use a hash map to map stops to routes for efficient neighbor lookup.
  • Track visited routes to avoid cycles and redundant processing.
  • Handle edge cases: source equals target (0 buses), no routes contain source or target (-1).
  • Time complexity: O(N * S) where N is number of routes and S is average stops per route, but can be optimized with early termination.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.