Detect a Currency Arbitrage Loop in Marketplace Exchange Rates
Last updated: November 29, 2026
Quick Overview
Amazon's global marketplaces convert between currencies using published rates. Given a list of directed rates, find a cycle of conversions whose product of rates exceeds 1 and return it, or return an empty list if none exists.
Amazon
November 29, 20260
0
0 solved
Amazon's global marketplaces convert between currencies using published rates. Given a list of directed rates, find a cycle of conversions whose product of rates exceeds 1 and return it, or return an empty list if none exists.
Payments and treasury teams must guard against inconsistent rate tables that allow money to be created by converting in a loop. Interviewers check the -log transform that turns a profitable loop into a negative cycle, and correct cycle reconstruction from Bellman-Ford parents.
What the Interviewer Expects
- Transform each rate r into edge weight -log(r)
- Explain why a product above 1 is a negative-weight cycle
- Run Bellman-Ford from a virtual source (all distances 0)
- Use the n-th iteration relaxation to locate a node on or leading to the cycle
- Walk parent pointers n times to land inside the cycle, then extract it
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 do floating point errors affect detection, and how would you add a tolerance?
- How would you find the most profitable cycle rather than any?
- How would you monitor this incrementally as rates update every second?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: currencies 0..n-1 and directed edges (a, b, rate) meaning one unit of a buys rate units of b. Output: a list of currencies forming a cycle with product of rates greater than 1 (first curren...
High-Level Design
A cycle's product exceeds 1 exactly when the sum of -log(rate) over it is negative. Start every distance at 0, which acts like a virtual source connected to all nodes, so cycles anywhere are found. ...