i circles its loop of stops loops[i] forever: it visits them in order and, after the last one, goes back to the first.
You are standing at stop start and have not boarded anything yet. You need to reach stop finish, and you can only travel by shuttle; you may change shuttles at any stop that both of them serve.
Return the smallest number of shuttles you have to board along the way, or -1 if the destination cannot be reached.loops=[[4, 9, 2], [9, 11], [11, 30, 7]], start=4, finish=7 → 3
Ride shuttle 0 to stop 9, change to shuttle 1 for stop 11, then shuttle 2 reaches 7: three boardings.
loops=[[1, 3], [5, 8]], start=3, finish=8 → -1
The loops share no stop, so stop 8 cannot be reached from stop 3.
loops=[[6, 2]], start=5, finish=5 → 0
We are already at the destination, so no boarding is needed.
loops=[[4, 9, 2], [9, 11], [11, 30, 7]], start=4, finish=7
3
Run checks the first 3 tests in your browser. Submit checks all 80 tests on the server, hidden ones included.