Transit shortest route
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.
fewest_interchange_hops(links: list[str], start: str, finish: str) → int[["Bank>Oval","Oval>Kings","Kings>Pier"],"Bank","Pier"]out3[["Bank>Oval","Oval>Kings","Kings>Pier","Bank>Pier"],"Bank","Pier"]out1[["Bank>Oval","Kings>Pier"],"Bank","Pier"]out-1State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
[["Bank>Oval","Oval>Kings","Kings>Pier"],"Bank","Pier"]3not run yetsample[["Bank>Oval","Oval>Kings","Kings>Pier","Bank>Pier"],"Bank","Pier"]1not run yetsample[["Bank>Oval","Kings>Pier"],"Bank","Pier"]-1not run yetsample