Detect a Profitable Arbitrage Cycle Across Currency Pairs

Last updated: November 29, 2026

Quick Overview

Given directed exchange rates between assets, determine whether some cycle of conversions returns more of the starting asset than you began with, and return one such cycle.

Coinbase
Coding & Algorithms
Software Engineer
Coinbase
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given directed exchange rates between assets, determine whether some cycle of conversions returns more of the starting asset than you began with, and return one such cycle.

With hundreds of assets and many quoted pairs on Coinbase, an internal pricing service must catch inconsistent rates before they are exploited. The interviewer expects the log transform that turns a product into a sum, Bellman-Ford negative cycle detection and correct cycle reconstruction.

What the Interviewer Expects
  • Transform rates with weight = -log(rate) so a profitable cycle is a negative cycle
  • Use Bellman-Ford from a virtual source so every component is covered
  • Reconstruct the cycle by stepping back n predecessors before walking it
  • Address floating point tolerance
  • State O(V * E) complexity and when that is acceptable
Key Topics to Cover
shortest paths
Bellman-Ford
negative cycles
graphs
logarithms
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you account for trading fees and spreads on each edge?
  • How would you find the most profitable cycle, not just any one?
  • Rates update every few milliseconds; how do you avoid recomputing from scratch?
  • Why does Dijkstra not work here?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: (src, dst, rate) meaning 1 src buys rate dst. A cycle is profitable when the product of its rates exceeds 1. Return the cycle as a list of assets with the start repeated at the end, or None...

High-Level Design

Product greater than 1 means the sum of log(rate) is positive, so with weights -log(rate) the cycle has negative total weight. Bellman-Ford finds negative cycles: after V-1 relaxation rounds all s...


Submit Your Answer
Markdown supported