Currency Arbitrage Cycle
Updated
Problem statement
You trade between n currencies numbered from 0 to n - 1. Each entry conversions[i] = [from, to] says you can convert currency from into currency to: 1 unit of from becomes rates[i] units of to. A conversion works only in the listed direction.
A cycle is a sequence of conversions that starts and ends at the same currency and visits no other currency twice. Going once around a cycle multiplies your money by the product of its rates. An arbitrage is a cycle whose product is greater than 1: you end with more of the starting currency than you began with.
Decide whether an arbitrage exists. If it does, return the currencies of the arbitrage cycle in conversion order, starting and ending at the smallest currency on the cycle, for example [1, 2, 3, 1]. If there is no arbitrage, return an empty list.
The input has at most one arbitrage cycle (the same cycle started at a different currency counts once), so the answer is unique. Also, no cycle's product is close to 1, so ordinary floating-point rounding cannot change the answer.
Aim for O(n * m) time, where m is the number of conversions.
Function
findArbitrage(n: int, conversions: int[][], rates: double[]) → int[]Examples
Example 1
n = 3conversions = [[0,1],[1,2],[2,0],[1,0],[2,1],[0,2]]rates = [0.9,0.8,1.4,1.1,1.2,0.7]return = [0,1,2,0]Start with 1 unit of currency 0. Converting to currency 1 gives 0.9, then to currency 2 gives 0.9 * 0.8 = 0.72, and back to currency 0 gives 0.72 * 1.4 = 1.008, more than the 1 unit we started with. Every other cycle loses money: 0 → 2 → 1 → 0 has product 0.7 * 1.2 * 1.1 = 0.924, and the round trips have products 0.99, 0.96 and 0.98.
Example 2
n = 3conversions = [[0,1],[1,0],[1,2],[2,1],[0,2],[2,0]]rates = [2.0,0.49,3.0,0.33,5.9,0.165]return = []The round trips have products 2.0 * 0.49 = 0.98, 3.0 * 0.33 = 0.99 and 5.9 * 0.165 = 0.9735. The two cycles through all three currencies have products 2.0 * 3.0 * 0.165 = 0.99 and 5.9 * 0.33 * 0.49 = 0.95403. No cycle has a product above 1, so there is no arbitrage.
Example 3
n = 4conversions = [[3,1],[1,2],[2,3],[0,3],[1,3]]rates = [2.0,0.8,0.65,1.5,0.45]return = [1,2,3,1]The cycle 3 → 1 → 2 → 3 has product 2.0 * 0.8 * 0.65 = 1.04. Its smallest currency is 1, so it is returned as [1, 2, 3, 1]. The only other cycle, 1 → 3 → 1, has product 0.45 * 2.0 = 0.9. Currency 0 can convert into the cycle, but nothing converts back into currency 0, so it is on no cycle.
Constraints
2 <= n <= 1001 <= conversions.length <= n * (n - 1)conversions[i].length == 20 <= conversions[i][0], conversions[i][1] < nconversions[i][0] != conversions[i][1]- No pair
[from, to]appears twice inconversions. rates.length == conversions.length0.01 <= rates[i] <= 100- The product of every cycle is greater than
1.001or less than0.999, and at most one cycle has a product greater than1.
More Citadel Phone Screen questions
- Speed Up a Slow FunctionOA · PHONE SCREEN · Seen Nov 2026
- Portfolio Tickers with Constant-Time Random PickPHONE SCREEN · Seen Nov 2026
- Square Root FunctionPHONE SCREEN · Seen Oct 2026
- Reachable Transfer PositionsPHONE SCREEN · Seen Oct 2026
- Spreadsheet Formula DependenciesPHONE SCREEN · Seen Oct 2026
- Order Book with Cancel by Order IDPHONE SCREEN · Seen Sep 2026
- Smart Queue of Latest PricesPHONE SCREEN · Seen Sep 2026
- Merge Price-Delta FeedsPHONE SCREEN · Seen Sep 2026
- Reconcile Unmatched Trades with Timestamp TolerancePHONE SCREEN · Seen Sep 2026
- Top Ten Trades by Notional ValuePHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
- Cheapest Flights Within K StopsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Shortest Word Chain Between Two WordsFanatics · PHONE SCREEN
- Shortest Paths in a Nonnegative Directed GraphNation with NaMo · PHONE SCREEN
- Shortest Path Node Count Avoiding Broken NodesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Dijkstra Shortest Paths in a Weighted Undirected GraphGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Maximum Survival Time in a Graph PursuitZip · PHONE SCREENZip interview questions
- Shortest Distances From an Adjacency MatrixBoston Consulting Group · PHONE SCREENBoston Consulting Group interview questions
- Shortest Path with Directional Move CostsThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
- Find and Reconstruct a Binary-Matrix PathMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
Citadel interview experiences
- Citadel Securities Quant Researcher Intern Loop: 1 Experience
- Citadel Securities Research Engineer Interview: 1 Experience
- Citadel Securities SWE Intern First Round: 2 Experiences
- Citadel Securities Experienced SWE Interviews: 1 Experience
- Citadel SWE Intern Later Rounds and Superday: 13 Experiences
- Citadel SWE Intern First-Round Questions: 20 Experiences