Detect currency arbitrage with costs
Problem Description
You are provided with a KxK matrix, R, representing currency exchange rates. R[i][j] denotes the amount of currency j that can be obtained for one unit of currency i. For all i, R[i][i] is guaranteed to be 1, meaning one unit of a currency exchanges for one unit of itself.
A transaction cost of 0.01% of the initial amount is incurred for each completed closed cycle of exchanges. This cost is applied once per cycle.
Your task is to determine if there exists any closed cycle of currency exchanges that, after accounting for the 0.01% transaction cost, results in a strictly higher final amount than the initial amount. Return true if such an arbitrage opportunity exists, otherwise return false.
AI interview prep
Core dilemma
Transforming a multiplicative profit-maximization problem with a cycle-specific transaction cost into an additive shortest/longest path problem on a graph, while ensuring numerical stability and efficiently detecting cycles against a specific non-zero threshold.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Detect currency arbitrage with costs
Problem Description
You are provided with a KxK matrix, R, representing currency exchange rates. R[i][j] denotes the amount of currency j that can be obtained for one unit of currency i. For all i, R[i][i] is guaranteed to be 1, meaning one unit of a currency exchanges for one unit of itself.
A transaction cost of 0.01% of the initial amount is incurred for each completed closed cycle of exchanges. This cost is applied once per cycle.
Your task is to determine if there exists any closed cycle of currency exchanges that, after accounting for the 0.01% transaction cost, results in a strictly higher final amount than the initial amount. Return true if such an arbitrage opportunity exists, otherwise return false.