Best Exchange Rate Path Across Order Books With a Hop Limit

Last updated: November 29, 2026

Quick Overview

Given directed currency order books, each with an effective rate net of fees, find the path from a source currency to a destination currency that maximises delivered amount per unit sent, using at most k books (hops), and return the rate and the path.

Ripple
Coding & Algorithms
Software Engineer
Ripple
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given directed currency order books, each with an effective rate net of fees, find the path from a source currency to a destination currency that maximises delivered amount per unit sent, using at most k books (hops), and return the rate and the path.

Cross-currency payments on the XRP Ledger can route through order books with XRP or a stablecoin as a bridge, and path finding is a core RippleX and Ripple Payments concern. The interviewer is checking whether you adapt shortest-path ideas to multiplicative weights and a hop budget, and whether you notice that plain Dijkstra does not apply.

What the Interviewer Expects
  • Model currencies as nodes and books as weighted directed edges
  • Explain why the hop limit calls for a Bellman-Ford style round structure
  • Use the previous round's values within a round to respect the hop budget
  • Reconstruct the path, not just the rate
  • Discuss cycles and arbitrage
Key Topics to Cover
Bellman-Ford
Graph Search
Hop-Constrained Paths
Currency Conversion
Arbitrage
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
  • How does the answer change when books have finite depth so the rate worsens as the amount grows?
  • How would you detect an arbitrage cycle in this graph?
  • Why does the ledger cap path length in real payments?
  • How would you handle rates as exact rationals instead of floats?
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

Input: a list of (from, to, rate) where rate is units of to received per unit of from after fees, plus src, dst, and max_hops. Output: the best product of rates along a simple path with at...

High-Level Design

Maximising a product of positive rates is equivalent to minimising the sum of −log⁡(rate)-\log(\text{rate}), which is a shortest-path problem with possibly negative weights, so Dijkstra is out. A hop limit is ...


Submit Your Answer
Markdown supported

Related Questions