Detect a Crypto Conversion Arbitrage Cycle With Bellman Ford
Last updated: November 29, 2026
Quick Overview
Given exchange rates between currencies and tokens, where a rate means one unit of the source buys that many units of the target, find any cycle of conversions whose product of rates exceeds one and return it, or report that none exists.
DRW
November 29, 20260
0
0 solved
Given exchange rates between currencies and tokens, where a rate means one unit of the source buys that many units of the target, find any cycle of conversions whose product of rates exceeds one and return it, or report that none exists.
DRW's crypto arm, Cumberland, trades across many venues and pairs, so finding cross rate inconsistencies is a direct fit. The interviewer checks the log transform to turn products into sums, correct negative cycle detection and reconstruction, and awareness that fees and floating point make real arbitrage rarer than the math suggests.
What the Interviewer Expects
- Transforms rates with negative logs so a profitable cycle is a negative cycle
- Runs Bellman Ford from a virtual source so any cycle is reachable
- Detects a relaxation in the n-th round
- Walks predecessors n steps to land inside the cycle before extracting it
- Uses a tolerance for float noise and mentions fees
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you include per trade fees and size limits?
- Rates update thousands of times a second: can you avoid rerunning from scratch?
- Why does Dijkstra not work here?
- How would you find the most profitable cycle rather than any cycle, and why is that harder?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: list of currencies and directed quotes (a, b, rate). Output: a cycle such as [USD, BTC, ETH, USD] with rate product above 1, or None. Floating point noise must not produce fake cycles....
High-Level Design
A product of rates above 1 means the sum of -log(rate) is below 0, so arbitrage is exactly a negative cycle. Start every distance at 0, equivalent to a virtual source with zero edges to all nodes. R...