New update is available. Click here to update.

Last Updated: 19 Mar, 2021

Difficulty: Moderate

```
If the bus route is [3, 6, 7], then it will travel in sequence
3 > 6 > 7 > 3 > 6 > 7….
```

```
Values of A[i] are distinct.
```

```
The first line contains a single integer ‘T’ denoting the number of test cases.
The first line of the test case contains ‘N’, ‘SOURCE’, ‘TARGET’ denoting the number of buses, source station, and target station.
The next ‘N’ lines contain the stations that the bus will travel to.
The first integer of the ith line contains the total number of bus stations ith bus will travel to.
The next A[i][j] integers denote the bus station’s number of ith bus.
```

```
For each test case, return the single integer denoting the minimum number of buses to take to travel from source to destination. If it is not possible to reach destination return -1.
```

```
You don’t need to print anything. It has already been taken care of. Just implement the given function.
```

```
1 <= ‘T’ <= 10
1 <= ‘N’ <= 400
1 <= sum(length of A[i]) <= 10^5
0 <= A[i][j], ‘SOURCE’, ‘TARGET’ <=10^6
Time Limit: 1 sec
```

SIMILAR PROBLEMS

Longest Subarray With Zero Sum

Posted: 3 Nov, 2022

Difficulty: Moderate

Distance to a Cycle in Undirected Graph

Posted: 7 Nov, 2022

Difficulty: Moderate

Merge Two Sorted Arrays Without Extra Space

Posted: 19 Nov, 2022

Difficulty: Moderate

Ninja And The Strictly Increasing Array

Posted: 27 Nov, 2022

Difficulty: Moderate

Negative To The End

Posted: 16 Dec, 2022

Difficulty: Easy

Popular Interview Problems: