Breadth-First Search pattern
Bus Routes
Given a list of bus routes where each route is a repeating sequence of stops, return the fewest buses you must take to travel from a source stop to a target stop, or -1 if it is impossible. Watch it run step by step, then write your own pseudocode and get it checked by AI.
- LeetCode 815
- Hard
- 1 approach
Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.
Breadth-First SearchLeetCode 815
Hard
The approach
- 01 BFS where states are routes O(S²)O(N + S) space
What you will learn
- How to read Bus Routes and spot the breadth-first search pattern in it
- BFS where states are routes: O(S²) time, O(N + S) space
- The pseudocode for each approach, its line lit as the animation runs
- Practice: write your own pseudocode and get it checked
More Breadth-First Search
See Bus Routes run, step by step
Sign in and this page opens on the animation, with all 8 Breadth-First Search problems beside it.
DSA comes with the all labs plan and every ChaiCode batch.