#124Hard#55 in Snap's list· asked at 7 companies
Bus Routes
Hosted on LeetCode
Solve it on LeetCode, track it here.
This problem's full statement lives on LeetCode. Open it in a new tab, then come back to mark it solved, add notes and keep your streak.
LeetCode Premium locked?
Most company-tagged LeetCode problems are behind Premium. If you have ChatGPT Plus or Claude Pro, ask it for the full statement, examples and constraints. The buttons below open a chat with the prompt already filled in.
What we know
Example 1
Input: routes = [[1,2,7],[3,6,7]], source = 1, target = 6 Output: 2
Take bus 0 from 1 to 7, then bus 1 from 7 to 6.
Example 2
Input: routes = [[7,12],[4,5,15],[6],[15,19],[9,12,13]], source = 15, target = 12 Output: -1
Constraints
- •
1 <= routes.length <= 500 - •
1 <= routes[i].length <= 10^5 - •
All the values of
routes[i]are unique. - •
sum(routes[i].length) <= 10^5 - •
0 <= source, target < 10^6