Search⌘ K
AI Features

Solution: Bus Routes

Explore how to find the minimum number of buses needed to travel between two stations by applying BFS on a graph constructed from bus routes. Learn to build adjacency lists, implement BFS traversal, and evaluate the algorithm's time and space complexity in solving routing problems.

Statement

You are given an array, routes, representing bus routes where routes[i] is a bus route that the ithi^{th} 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:

  • 11 \le routes.length 50\le 50
...