Your question is BFS Shortest Path Coding. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
BNSF Railway models a simplified network of locations as an unweighted graph. Each edge represents a directly connected route segment, and every segment has equal cost. Given the graph, a starting location, and a destination, return the shortest path as an ordered list of locations.
If the destination cannot be reached, return an empty list. If the start and destination are the same, return a list containing that location.
Implement shortest_route(graph, start, destination).
graph is a dictionary mapping each location name to a list of directly connected location names.A to B does not imply an edge from B to A.start and destination are strings present as keys in graph.start to destination, including both endpoints.start and destination are keys in graphdef shortest_route(graph, start, destination):