Bus Routes

Try to solve the Bus Routes problem.

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, dest. Return the minimum number of buses someone must take to travel from src to dest, or return -1 if there is no route.

Constraints:

  • 1≤1 \le routes.length ≤50\le 50
  • 1≤1 \le routes[i].length ≤100\le 100
  • 0≤0 \le routes[i][j] <1000< 1000
  • 0≤0 \le src, dest <1000< 1000

Examples

Create a free account to view this lesson.

Continue your learning journey with a 14-day free trial.

By signing up, you agree to Educative's Terms of Service and Privacy Policy