Detect a Profitable Currency Conversion Cycle Across FX Quotes

Last updated: November 29, 2026

Quick Overview

Given a set of currencies and directional FX quotes (units of B per unit of A), determine whether some cycle of conversions starting and ending in the same currency yields more than you started with, and return one such cycle.

Deutsche Bank
Coding & Algorithms
Software Engineer
Deutsche Bank
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given a set of currencies and directional FX quotes (units of B per unit of A), determine whether some cycle of conversions starting and ending in the same currency yields more than you started with, and return one such cycle.

Deutsche Bank is one of the large FX dealers, and consistency checks on quoted cross rates matter for pricing engines and for guarding against stale or wrong quotes. An onsite hard coding question like this tests whether the candidate can turn a multiplicative problem into a shortest-path problem and recover the negative cycle correctly.

What the Interviewer Expects
  • Transform product of rates into a sum using negative logarithms
  • Recognise a profitable cycle as a negative-weight cycle
  • Run Bellman-Ford from a virtual source to reach all components
  • Recover the cycle by walking parent pointers n steps first
  • Use an epsilon to avoid floating-point false positives
Key Topics to Cover
Bellman-Ford
Negative cycles
Logarithm transform
Graph algorithms
Floating-point tolerance
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 would you find the most profitable cycle rather than any cycle?
  • Quotes have bid and ask: how does that change the graph?
  • Quotes update thousands of times a second: how would you avoid recomputing from scratch?
  • How would you handle a cycle that is only profitable for tiny notional because of liquidity limits?
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: list of currency codes and a dict (src, dst) -> rate. Output: a list like ['USD', 'EUR', 'GBP', 'USD'] whose product of rates exceeds 1, or None. Graph may be disconnected and not every p...

High-Level Design

A cycle is profitable iff ∏ri>1\prod r_i > 1 iff ∑−ln⁡ri<0\sum -\ln r_i < 0. So weight each edge w=−ln⁡rw = -\ln r and look for a negative cycle. Bellman-Ford does that in O(VE). Initialising all distances to 0 is t...


Submit Your Answer
Markdown supported

Related Questions