Your question is Shortest Path in Currency Graph. 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.
Wise. Energy models supported currency conversions as a directed graph. Each currency is a node, and an edge from currency A to currency B means a direct conversion is available. Given the graph, a source currency, and a target currency, return a route with the fewest conversion steps.
Implement find_shortest_conversion_path(graph, source, target) using Breadth-First Search. The returned route must include both endpoints. If the currencies are identical, return a one-element route. If no route exists, return an empty list. Treat edges as directed, and do not mutate the input graph.
If multiple shortest routes exist, return the one discovered first by BFS, processing each adjacency list in its given order.
graph is a dictionary mapping currency codes to lists of directly reachable currency codes.source and target are strings.[] when no route exists.graph.def find_shortest_conversion_path(graph, source, target):