Reported September 2026
Pinterestbreadth first search

Minimum Bus Routes to a Destination

Reported by candidates from Pinterest's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Pinterest OA. Under 2s to a working solution.
Founder's read

The Pinterest OA reported in September 2026 looks like a transit puzzle, but it's a shortest-path problem in disguise. Minimum buses from a source stop to a target stop means BFS, and the trick is choosing what the nodes are. If you've got an invite in your inbox, this is the one to recognize on sight. Stops are the obvious nodes, but routes are the better ones, because the cost is counted per boarding. Get that framing right and the code is about 25 lines. StealthCoder is the safety net if you blank on the live OA, but you can walk in knowing this one.

The problem

Each row in routes lists all stops served by one bus route. Boarding a route costs one bus; after boarding, you may travel to any stop on it. Return the minimum buses needed to travel from sourceStop to targetStop, or -1 if impossible.

Function
minimumBusRoutes(routes: int[][], sourceStop: int, targetStop: int) → int

Examples
Example 1
routes = [[1,2,7],[3,6,7]]
sourceStop = 1
targetStop = 6
return = 2
Take the first route to 7, then the second to 6.
Example 2
routes = [[1,5,7],[3,5]]
sourceStop = 5
targetStop = 5
return = 0
The trip is already complete.
Example 3
routes = [[1,2],[3,4]]
sourceStop = 1
targetStop = 4
return = -1
The route groups are disconnected.

Constraints
1 <= routes.length <= 500.
The total number of listed stops is at most 10^5.
Stops on one route are unique.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Build a map from each stop to the list of routes that serve it. Then run BFS over routes, not stops. Start by queuing every route that contains sourceStop with a count of 1. Pop a route, and if it contains targetStop, return its count. Otherwise, for each stop on that route, push every unvisited route from the map and mark it visited with count plus one. Handle the edge case first: if source equals target, return 0. The common pitfall is BFS over stops, where every stop-to-stop move costs one and you overcount, or you revisit routes thousands of times and time out. Mark visited routes AND clear or skip stops you've already expanded, since the total stop count reaches 10^5. If the queue empties, return -1. StealthCoder is the hedge if the live OA wipes your memory of this setup.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Minimum Bus Routes to a Destination cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as bus routes. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Pinterest's OA.

Pinterest reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimum Bus Routes to a Destination FAQ

What's the trick in Minimum Bus Routes to a Destination?+

Treat each route as a graph node, not each stop. Two routes connect if they share a stop. BFS then counts buses directly, since each level is one more boarding. Build a stop-to-routes hash map first, and you're most of the way there.

How hard is this Pinterest OA question really?+

It's a LeetCode hard-tagged problem, but it's mostly a BFS with one modeling decision. If you know BFS and hash maps, the code is short. The difficulty is seeing routes as nodes and avoiding a time-out from repeated expansion.

Why does BFS over stops give wrong answers?+

Moving between stops on the same route costs nothing extra, but a plain stop-level BFS charges one per hop. You'd overcount buses. Either BFS on routes, or on stops while adding a whole route's stops at the same level.

What edge cases should I test?+

Source equals target returns 0, as in Example 2. Disconnected route groups return -1, as in Example 3. Also test a source stop that appears on no route, and a target that no route serves. Both should return -1 unless source equals target.

How do I prepare in 48 hours for this pattern?+

Write BFS on an implicit graph from scratch twice, using a hash map for adjacency and a visited set. Then solve this problem once without looking. Focus on the visited logic, since that's where most time-outs come from.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Pinterest.

OA at Pinterest?
Invisible during screen share
Get it