← Pinterest Interview Insights

Pinterest·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Phone screen for a Software Engineer role at Pinterest. One algorithmic question, BFS-heavy, the kind that looks manageable until you're actually in it.

Questions Asked (1)

Q1

Given a list of bus routes where each route is a set of stops, find the minimum number of buses you need to take to travel from a source stop to a destination stop.

Algorithms & Data Structures
Author's notes

BFS but not on stops, on routes.

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 connect routes that share at least one stop. Then perform BFS from all routes containing the source stop to find the minimum number of routes (buses) to reach any route containing the destination stop. Return the number of buses as the BFS level + 1 (or 0 if source equals destination).

Pro tip: Clarify edge cases upfront: if source equals destination, answer is 0; if no route contains source or destination, return -1. Also mention that precomputing stop-to-routes mapping optimizes the BFS.

1. Clarify and Define

Confirm the problem details: each bus route is a set of stops, you can transfer between routes at shared stops, and you want the minimum number of buses. Ask about edge cases like source == destination or unreachable stops.

2. Model as Graph

Represent each bus route as a node. Connect two route nodes if they share at least one stop. This transforms the problem into finding the shortest path in an unweighted graph.

3. 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 are reachable from a given stop.

4. BFS for Minimum Buses

Start BFS from all routes containing the source stop. For each route, explore all its stops, and for each stop, enqueue all unvisited routes that contain that stop. Track the number of buses (BFS levels). Stop when a route containing the destination is found.

5. Handle Edge Cases and Return

If source == destination, return 0. If BFS exhausts without reaching destination, return -1. Otherwise, return the number of buses taken (BFS level + 1).

Key Points to Mention

  • Graph modeling: routes as nodes, edges between routes sharing stops.
  • BFS guarantees shortest path in unweighted graph.
  • Use a stop-to-routes hash map for efficient neighbor lookup.
  • Track visited routes to avoid cycles and redundant work.
  • Time complexity: O(N * S) where N is number of routes and S is average stops per route, but can be optimized to O(total stops) with mapping.
  • Space complexity: O(total stops + total route-stop connections).

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