Detect Triangular FX Arbitrage Across Quoted Currency Pairs
Last updated: November 29, 2026
Quick Overview
Given a set of directed FX quotes where each says one unit of currency A buys r units of currency B, determine whether some cycle of conversions returns more than you started with, and if so return one such cycle.
Citi
November 29, 20260
0
0 solved
Given a set of directed FX quotes where each says one unit of currency A buys r units of currency B, determine whether some cycle of conversions returns more than you started with, and if so return one such cycle.
Citi is one of the largest FX dealers, and its pricing engines must never publish a set of cross rates that lets a client cycle through currencies for profit. The interviewer wants the log transform to a negative-cycle problem, a correct Bellman-Ford with cycle recovery, and numerical care.
What the Interviewer Expects
- Turn products of rates into sums with negative logs
- Recognize a profitable loop as a negative cycle
- Run Bellman-Ford from a virtual source so all components are covered
- Recover the cycle by walking parents n steps first
- Use a tolerance for floating point noise
- Discuss bid/ask spreads and why real arbitrage is rare
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?
- How do bid and ask quotes change the graph?
- Quotes update thousands of times a second: how would you check incrementally?
- Why do you walk back n parent steps before extracting the cycle?
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). A cycle c1 -> c2 -> ... -> c1 is profitable when the product of rates exceeds 1. Return the cycle as a list of currencies starting and ending at the same one, or `No...
High-Level Design
Product greater than 1 means sum of logs greater than 0, which means sum of -log(rate) below 0. So set edge weight w = -log(rate) and look for a negative cycle. Bellman-Ford finds one: after n min...