Find the Best FX Conversion Path and Detect Arbitrage
Last updated: November 29, 2026
Quick Overview
Given directed currency pairs with conversion rates, return the best achievable rate and path from a source currency to a target currency, and raise an error if an arbitrage loop can make that rate unbounded.
J.P. Morgan
November 29, 20260
0
0 solved
Given directed currency pairs with conversion rates, return the best achievable rate and path from a source currency to a target currency, and raise an error if an arbitrage loop can make that rate unbounded.
J.P. Morgan runs one of the largest FX businesses in the world, so FX graph problems appear in Markets technology onsites. The interviewer is checking that you transform a multiplicative best-path problem into shortest paths with negative logs, choose Bellman-Ford because weights can be negative, and handle negative cycles that only matter if they can reach the target.
What the Interviewer Expects
- Convert products of rates to sums with -log(rate)
- Pick Bellman-Ford over Dijkstra because weights can be negative
- Detect negative cycles and propagate their reach to decide if the target is affected
- Reconstruct the conversion path with predecessor pointers
- Discuss floating point tolerance in comparisons
- State O(V * E) time
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 account for bid/ask spreads and per-trade fees?
- If quotes update thousands of times per second, how would you recompute incrementally?
- How would you cap path length at three hops for execution risk?
- Why is a detected 'arbitrage' often not tradable in practice?
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: list of (from, to, rate) meaning one unit of from buys rate units of to. Output: (best_rate, path) from source to target; (0.0, []) if unreachable. If some cycle multiplies to more ...
High-Level Design
Maximizing equals minimizing . Rates above 1 make negative weights, so Dijkstra is invalid and Bellman-Ford is the right tool. A product above 1 around a loop is a negative...