Solution: Bus Routes
Explore how to solve the bus routes problem by creating an adjacency list and applying the Breadth-First Search algorithm. Learn to map bus stations to routes and efficiently determine the minimum number of buses needed to travel from a source to a destination station. This lesson helps you develop confidence in solving graph traversal problems in coding interviews.
We'll cover the following...
We'll cover the following...
Statement
You are given an array, routes, representing bus routes where routes[i] is a bus route that the bus repeats forever. Every route contains one or more stations. You have also been given the source station, src, and a destination station, des. Return the minimum number of buses someone must take to travel from src to dest, or return -1 if there is no route.
Constraints:
-
routes.length