Given a list of currency codes currencies and a full matrix rates where rates[i][j] is the exchange rate from currency to currency , determine if a compounding currency arbitrage cycle exists.
If an arbitrage opportunity exists, reconstruct the exact ordered sequence of currency codes forming the cycle (e.g., ['USD', 'EUR', 'GBP', 'USD']) and compute the realized multiplicative return factor .
Your Task
Implement reconstruct_arbitrage_cycle(currencies: list[str], rates: list[list[float]]) -> tuple[bool, list[str], float] that returns:
has_arbitrage: boolean True if an arbitrage cycle exists, False otherwise.cycle: list of currency ticker strings starting and ending with the same currency (empty list if no arbitrage).profit_factor: float compounding return (rounded to 6 decimal places; returns 1.0 if no arbitrage).Constraints
Examples
currencies = ['USD', 'EUR', 'GBP']
rates = [
[1.0, 0.85, 0.75],
[1.18, 1.0, 0.88],
[1.34, 1.14, 1.0]
]
# Cycle USD -> EUR -> GBP -> USD: 0.85 * 0.88 * 1.34 = 1.00232 > 1.0
# Output: (True, ['USD', 'EUR', 'GBP', 'USD'], 1.00232)