Best Currency Conversion Rate Using at Most K Exchanges
Last updated: November 29, 2026
Quick Overview
Given quoted exchange rates between currency pairs (each usable in both directions at the inverse rate), a source currency, a target currency and an integer K, return the largest amount of target currency obtainable for 1 unit of source using at most K conversions, or -1 if unreachable.
Revolut
November 29, 20260
0
0 solved
Given quoted exchange rates between currency pairs (each usable in both directions at the inverse rate), a source currency, a target currency and an integer K, return the largest amount of target currency obtainable for 1 unit of source using at most K conversions, or -1 if unreachable.
Revolut supports exchange across dozens of fiat currencies and crypto assets, so routing a conversion through intermediate currencies is a natural interview theme. The interviewer looks for a correct hop-bounded relaxation, and for awareness that cycles with product above 1 make plain Dijkstra unsafe.
What the Interviewer Expects
- Model currencies as nodes and rates as multiplicative edge weights, adding inverse edges
- Explain why maximizing a product with possible arbitrage cycles breaks greedy Dijkstra
- Use K rounds of Bellman-Ford style relaxation from a snapshot of the previous round
- State O(K * E) time and O(V) space
- Handle source equal to target and unreachable targets
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 detect an arbitrage cycle in the rate table?
- How do you also return the path of currencies used?
- Each conversion charges a fixed 0.5% fee. How does the algorithm change?
- Rates update thousands of times per second. What would you precompute?
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: pairs as (a, b, rate) meaning 1 a buys rate b, and b converts back to a at 1/rate. Find the maximum product of rates along a path from source to target with at most K edges. If source e...
High-Level Design
This is a hop-bounded longest path on products, equivalent to a shortest path on -log(rate). Negative weights can appear (any rate above 1 has negative -log) and cycles with total product above 1 ...