Detect Currency Arbitrage After a Cycle Fee
Company: Optiver
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Overview: You are given a matrix of positive currency exchange rates, where rates[i][j] units of currency j are received for one unit of currency i. Work through the function contract, boundary cases, correctness argument, and time and space complexity expected in a production-quality solution.
Constraints
- 1 <= n <= 50 and rates is an n by n matrix of positive finite numbers.
- A candidate sequence uses between one and n exchanges and may repeat currencies.
- Profit requires a completed cycle product strictly greater than 1.0001.
- Floating-point handling may tolerate ordinary roundoff but must preserve the stated threshold.
Examples
Input: ([[1.0]],)
Expected Output: False
Explanation: A one-currency identity exchange does not beat the fee threshold.
Input: ([[1.0001]],)
Expected Output: False
Explanation: A cycle equal to the stated threshold is not strictly profitable.
Hints
- Test one currency, a cycle exactly at the fee threshold, and one just above it.
- Include a profitable multi-currency cycle and a consistent-rate matrix whose cycles all multiply to one.
- Use a favorable path that does not return to its starting currency to confirm it does not qualify.