Transit shortest route

Write codeEasy16 minUber style

Your task

A journey planner stores a transit map as links, where each entry is a string like "Bank>Oval" naming one track segment between two stations. Trains run both ways along a segment, so the order inside an entry carries no meaning. A rider boarding at start wants to reach finish riding as few segments as possible, and each segment ridden counts as one hop. Return the smallest number of hops, 0 when start and finish name the same station, and -1 when no route exists, which includes the case where a station never appears on the map. The map may list the same segment twice, may list a segment from a station back to itself, and may contain loops.

Examples

fewest_interchange_hops(links: list[str], start: str, finish: str) -> int
Example 1
Inputfewest_interchange_hops(["Bank>Oval", "Oval>Kings", "Kings>Pier"], "Bank", "Pier")
Output3
Example 2
Inputfewest_interchange_hops(["Bank>Oval", "Oval>Kings", "Kings>Pier", "Bank>Pier"], "Bank", "Pier")
Output1
Example 3
Inputfewest_interchange_hops(["Bank>Oval", "Kings>Pier"], "Bank", "Pier")
Output-1