Given a list of currency relationships with exchange values (e.g. BTC - USD), find the best exchange rate from currency1 to currency2.
Each relationship is directed: [source, destination, rate] means one unit of source becomes rate units of destination. Return the maximum product of rates along any simple path. Return 1.0 when both currencies are equal and 0.0 when the destination is unreachable. Asked in the coding round 1 stage. Edge cases like self loops expected.
Function: def best_exchange_rate(rates, currency1, currency2):
rates is a list of [string, string, float] values. Do not reuse a currency within one path.
def best_exchange_rate(rates, currency1, currency2):