Detect Currency Arbitrage Cycles After Conversion Fees
Last updated: November 29, 2026
Quick Overview
Given exchange rates between currencies and a flat percentage fee charged on every conversion, determine whether some cycle of conversions returns more money than it started with, and if so return one such cycle and its gain.
PayPal
November 29, 20260
0
0 solved
Given exchange rates between currencies and a flat percentage fee charged on every conversion, determine whether some cycle of conversions returns more money than it started with, and if so return one such cycle and its gain.
PayPal converts currencies for cross-border payments and must make sure its own quoted rates, after spread and fees, never let a user loop conversions for profit. The interviewer expects the log transform to a shortest-path problem, Bellman-Ford with negative-cycle extraction, and care with floating-point tolerance.
What the Interviewer Expects
- Transform multiplication of rates into addition with negative logs
- Fold the per-conversion fee into each edge weight
- Use Bellman-Ford with a virtual source to detect any negative cycle
- Recover the cycle by walking predecessors n steps
- Use an epsilon to avoid flagging floating-point noise
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 find the most profitable cycle rather than any cycle?
- Rates update thousands of times per second; how do you avoid full recomputation?
- Why is Dijkstra not usable here?
- How would you treat rate quotes that expire at different times?
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: a list of currencies, directed rate quotes (src, dst, rate) meaning 1 unit of src buys rate units of dst, and a fee fraction applied to every conversion. Output: None if no profitable lo...
High-Level Design
A loop is profitable when the product of effective rates r * (1 - fee) exceeds 1. Taking -log turns that into a cycle with negative total weight, so the task is negative-cycle detection. Bellman-F...