FastPrepMinimum Bus Routes to a Destination
Problems/Minimum Bus Routes to a Destination

Minimum Bus Routes to a Destination

Google logoGoogle● HardNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report says the first round was a variant of the well-known Bus Routes problem, and discusses bus-stop and bus-route graph models. We use the usual goal of the fewest buses, and we define what equal stops and unreachable stops return. Our version is about 94% the same as the reported question.

Each row in routes lists the distinct stops served by one bus route. Boarding a route costs one bus; after boarding, you may travel to any stop on that route and transfer to another route serving the same stop.

Return the minimum number of buses needed to travel from sourceStop to targetStop. Return 0 when the two stops are equal and -1 when the destination is unreachable.

Function

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

Examples

Example 1

routes = [[1,2,7],[3,6,7]]sourceStop = 1targetStop = 6return = 2

Take the first route to stop 7, then transfer to the second route and reach 6.

Example 2

routes = [[1,2,3],[4,5,6]]sourceStop = 1targetStop = 6return = -1

The two routes share no stop, so no transfer connects the endpoints.

Example 3

routes = [[5,8],[8,9]]sourceStop = 5targetStop = 5return = 0

No bus is needed when the source already equals the destination.

Constraints

  • 1 <= routes.length <= 500.
  • 1 <= routes[i].length <= 100000.
  • The total number of route-stop entries is at most 200000.
  • Stops within one route are distinct integers in [0,10^9].
  • 0 <= sourceStop,targetStop <= 10^9.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Fewest Buses with the Full RouteMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Minimum Bus Routes to a DestinationPinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
  • Jump Game IVZomato / Eternal · ONSITE INTERVIEWZomato / Eternal interview questions
  • Largest Island After One FlipOracle · ONSITE INTERVIEWOracle interview questions
  • Find Duplicate Files in a FilesystemHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
  • Word LadderGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Word Ladder II: All Shortest TransformationsPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
  • Word Ladder IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Concurrent Web Crawler SimulationOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Currency Conversion RateAmazon · PHONE SCREEN · ONSITE INTERVIEW

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int minimumBusRoutes(int[][] routes, int sourceStop, int targetStop) {
        // Write your code here.
    }
}
Checking account…