Profitable Currency Exchange Cycle
Updated
Problem statement
The square matrix rates describes currency conversions. Exchanging one unit of currency i into currency j yields rates[i][j] units.
An exchange cycle begins and ends at the same currency and uses between 1 and rates.length exchanges, inclusive. Intermediate currencies may repeat. The exchange-rate product is applied to the starting amount, then one fee equal to 0.01% of the starting amount is charged.
Return true when some allowed cycle is strictly profitable after that one fee; otherwise return false.
Function
hasProfitableExchangeCycle(rates: double[][]) → booleanExamples
Example 1
rates = [[1.0,1.1,0.9],[0.9,1.0,1.1],[1.0,0.9,1.0]]return = trueThe cycle 0 -> 1 -> 2 -> 0 multiplies your money by 1.21. After the fee, you still have more than 1 unit for each unit you started with, so the answer is true.
Example 2
rates = [[1.0,0.9],[1.1,1.0]]return = falseGoing to the other currency and back multiplies your money by 0.99. Exchanging a currency into itself multiplies it by 1. None of these cycles makes a profit after the fee, so the answer is false.
Constraints
1 <= rates.length <= 40rates[i].length = rates.length10^-4 <= rates[i][j] <= 10^4rates[i][i] = 1- For every allowed cycle, the sum of the logarithms of its rates is at least
10^-10away from the break-even value. At that value, the cycle's gain exactly pays the fee.
More Optiver Online Assessment questions
- Overheat Prevention ControllerOA · Seen Nov 2026
- Power Cell BankOA · Seen Nov 2026
- Count Straight-Line Word Occurrences in a GridOA · Seen Sep 2026
- Fastest Average Speed over a Rolling KilometerOA · Seen Sep 2026
- Multi-Level Inventory Storage SystemOA · PHONE SCREEN · Seen Aug 2026
- Proportional Momentum Investment StatisticsOA · Seen Aug 2026
- Count Bounded Share TransactionsOA · Seen Aug 2026
- Count Ordered Size SequencesOA · Seen Aug 2026
- Construct Binary Tree S-ExpressionOA · Seen Jul 2026
- Days BetweenOA · Seen Jul 2026
Similar questions at other companies
- Count Routes in a Divisor GraphExpedia · OAExpedia interview questions
- At Most K Jumps with Quadratic Transition CostInfosys · OAInfosys interview questions
- Largest Consistent Visiting GroupAuxoAI · OA
- Maximum Signal Walk in a Server TreeTower Research Capital · OA
- Count Nondecreasing Digit-Sum ArraysMicrosoft · OAMicrosoft interview questions
- Jump Game with Prime-3 StepsUber · OAUber interview questions
- Minimum Numeric Code TransformationAdobe · OAAdobe interview questions
- Drone Delivery with Battery Swap StationsCisco · OACisco interview questions
- Match an XOR-Adjusted SumSquarepoint Capital · OASquarepoint Capital interview questions
- Count Numbers with a Prime Digit SumRippling · OARippling interview questions