I went straight to Bellman-Ford in my head because 'cycles' and 'rates' screamed arbitrage detection, but the twist is you're maximizing a product along a path, not minimizing a sum.
Model the problem as a graph where currencies are nodes and exchange rates are directed edges with weights equal to the negative logarithm of the rate. Then, for each day, compute the maximum amount reachable from the starting currency using a modified shortest path algorithm that handles negative cycles (arbitrage). Finally, combine the results from both days to find the maximum final amount in the target currency.
Pro tip: Emphasize that arbitrage cycles can be exploited by converting to the cycle currency, looping, and converting back, but only if the cycle is reachable and can reach the target. Also, mention that the order of days matters and you must optimize over all possible intermediate currencies after day 1.
Represent currencies as nodes and exchange rates as directed edges with weights = -log(rate). This converts multiplicative rates to additive costs, so maximizing amount becomes minimizing cost.
Detect negative cycles (product of rates > 1) using Bellman-Ford. For any currency reachable from a negative cycle, set its maximum amount to infinity (or a very large number) because you can exploit the cycle to increase money arbitrarily.
For day 1, compute the maximum amount of each currency starting from the initial amount. For day 2, compute the maximum amount of each currency starting from 1 unit (or from the amounts after day 1). Use Bellman-Ford with negative cycle handling.
For each currency C, the maximum amount after day 2 is max over C of (max amount of C after day 1) * (max amount of target from C on day 2). Take the maximum over all C.
Time complexity: O(V * E) per day for Bellman-Ford, where V is number of currencies and E is number of edges. Space: O(V) for distances. Mention that if negative cycles exist, additional O(V*E) to propagate infinities.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.