Find the Best FX Conversion Route Within a Leg Limit
Last updated: November 29, 2026
Quick Overview
Given exchange quotes from liquidity providers as directed edges with rates, find the conversion path from a source currency to a target currency that maximizes the received amount while using at most k conversion legs.
Remitly
November 29, 20260
0
0 solved
Given exchange quotes from liquidity providers as directed edges with rates, find the conversion path from a source currency to a target currency that maximizes the received amount while using at most k conversion legs.
Treasury at a remittance company can sometimes deliver more value by routing through an intermediate currency, but every extra leg adds settlement risk, so routes are capped. The interviewer is looking for a bounded-hop shortest-path idea adapted to multiplicative weights.
What the Interviewer Expects
- Recognizes this as a path problem with multiplicative weights
- Uses round-by-round relaxation so the leg limit is respected
- Explains why plain Dijkstra on -log(rate) can fail when rates exceed 1
- Returns the path, not only the value
- Discusses arbitrage cycles and why the hop bound matters
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 add a fixed fee per leg in addition to the rate?
- How do you detect an arbitrage cycle in the quote graph, and what should the system do about it?
- Quotes expire every few seconds. How do you keep route selection fresh without recomputing everything?
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 source, a target, and max_legs. Output: the best multiplier and the currency path. Unreachable within the limit returns (0.0, [])....
High-Level Design
This is Bellman-Ford limited to k rounds. Taking -log(rate) turns products into sums, but rates above 1 give negative weights, so Dijkstra is not safe. Instead run k rounds of relaxation; in each ro...