Find the Best FX Route Within a Hop Limit

Last updated: November 29, 2026

Quick Overview

Given a list of directed currency pairs with conversion rates, return the most destination currency obtainable for one unit of a source currency using at most k conversions, or -1 if unreachable.

Airwallex
Coding & Algorithms
Software Engineer
Airwallex
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given a list of directed currency pairs with conversion rates, return the most destination currency obtainable for one unit of a source currency using at most k conversions, or -1 if unreachable.

Fits an Airwallex treasury or FX engineering screen: liquidity providers quote some pairs directly and others only through a hub like USD, and each extra leg adds settlement risk, so routes are hop-limited. The interviewer looks for recognizing a bounded Bellman-Ford and handling the multiplicative objective cleanly.

What the Interviewer Expects
  • Models currencies as nodes and quotes as weighted directed edges
  • Recognizes the hop limit makes this bounded Bellman-Ford rather than Dijkstra
  • Relaxes from the previous round's values to respect the hop count
  • Explains why multiplying rates is equivalent to adding negative logs
  • Handles unreachable and source equals destination
Key Topics to Cover
Graphs
Bellman-Ford
Hop-limited paths
Log transform
FX routing
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • If the graph contains an arbitrage cycle, what does an unbounded version return, and how would you detect it?
  • How would you return the actual route, not only the rate?
  • Each leg also has a fixed fee in minor units: how does the objective 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 Problems
Sample Answer
Requirements

Edges (from, to, rate); maximize the product of rates along a path of at most k edges from src to dst. Return -1 if no path. Rates are positive....

High-Level Design

Dijkstra does not respect a hop limit (a cheaper long path can block a shorter one), so I use k rounds of relaxation. In round i, best[c] holds the best amount reachable in at most i hops. Each roun...


Submit Your Answer
Markdown supported

Related Questions