Bus Routes
Hard · Queue & Deque · about 30 minutes
Asked at Uber, Pinterest, Google, Amazon, Airbnb, Booking.com, Expedia Group, Zillow, Duolingo, Glean, Yelp, Match Group.
Bus i drives the loop of stops routes[i] over and over. You are standing at stop source, not yet on a bus, and want to get to stop target using buses only. What is the smallest number of different buses you need to ride? Return -1 if target can't be reached, and 0 if you're already there.