PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Optiver

Maximum Currency Conversion Rate

Last updated: Jul 1, 2026

Maximum Currency Conversion Rate

Company: Optiver

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Maximum Currency Conversion Rate You are given `N` currency exchange rate pairs. Each pair is a triple `(from_currency, to_currency, rate)`, meaning that 1 unit of `from_currency` can be exchanged for `rate` units of `to_currency`. All rates are strictly positive real numbers. Given a `source` currency and a `target` currency, find the **best (maximum) overall conversion rate** achievable by chaining one or more exchanges from `source` to `target`. Chaining exchanges multiplies their rates: converting through the sequence `A -> B -> C` yields an overall rate of `rate(A->B) * rate(B->C)`. Rules and assumptions: - Exchanges are **directional**: a pair `(A, B, r)` lets you convert `A` to `B` at rate `r`, but does **not** by itself allow converting `B` to `A`. A reverse rate is only available if it appears as its own pair in the input. - A conversion path must **not visit the same currency more than once** (simple paths only), so a path's length is bounded by the number of distinct currencies. - If the same directed pair `(from_currency, to_currency)` appears multiple times, use the one with the highest rate. - If `source == target`, the answer is `1.0`. - If `target` is unreachable from `source`, return `-1.0`. ### Input - `pairs`: a list of `N` triples `[from_currency, to_currency, rate]`, where currencies are strings (e.g., `"USD"`, `"EUR"`) and `rate` is a positive float. - `source`: the starting currency (string). - `target`: the desired currency (string). ### Output Return a single float: the maximum achievable conversion rate from `source` to `target`, or `-1.0` if no conversion path exists. Answers within `1e-6` relative or absolute tolerance are accepted. ### Example ``` pairs = [["USD", "EUR", 0.9], ["EUR", "GBP", 0.85], ["USD", "GBP", 0.7], ["GBP", "JPY", 190.0]] source = "USD" target = "JPY" ``` Output: ``` 145.35 ``` Explanation: the path `USD -> EUR -> GBP -> JPY` gives `0.9 * 0.85 * 190.0 = 145.35`, which beats the direct-ish alternative `USD -> GBP -> JPY = 0.7 * 190.0 = 133.0`. ### Constraints - `1 <= N <= 200` - Number of distinct currencies `<= 14` - Currency codes are non-empty strings of up to 10 uppercase letters - `0 < rate <= 10.0` - The final answer is guaranteed to fit in a standard 64-bit floating-point value (it will not exceed `1e9`) - `source` and `target` are guaranteed to appear in at least one pair

Related Interview Questions

  • Build and Validate a Binary Tree from Parent-Child Pairs - Optiver (medium)
  • Days Between Two Calendar Dates - Optiver (medium)
  • Thread-Safe Stock Inventory: Buy and Sell Without Overselling - Optiver (medium)
  • Find missing numbers in sequences - Optiver (hard)
  • Design a circular queue data structure - Optiver (medium)
|Home/Coding & Algorithms/Optiver

Maximum Currency Conversion Rate

Optiver logo
Optiver
Jan 31, 2025, 12:00 AM
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
0
0

Maximum Currency Conversion Rate

You are given N currency exchange rate pairs. Each pair is a triple (from_currency, to_currency, rate), meaning that 1 unit of from_currency can be exchanged for rate units of to_currency. All rates are strictly positive real numbers.

Given a source currency and a target currency, find the best (maximum) overall conversion rate achievable by chaining one or more exchanges from source to target. Chaining exchanges multiplies their rates: converting through the sequence A -> B -> C yields an overall rate of rate(A->B) * rate(B->C).

Rules and assumptions:

  • Exchanges are directional : a pair (A, B, r) lets you convert A to B at rate r , but does not by itself allow converting B to A . A reverse rate is only available if it appears as its own pair in the input.
  • A conversion path must not visit the same currency more than once (simple paths only), so a path's length is bounded by the number of distinct currencies.
  • If the same directed pair (from_currency, to_currency) appears multiple times, use the one with the highest rate.
  • If source == target , the answer is 1.0 .
  • If target is unreachable from source , return -1.0 .

Input

  • pairs : a list of N triples [from_currency, to_currency, rate] , where currencies are strings (e.g., "USD" , "EUR" ) and rate is a positive float.
  • source : the starting currency (string).
  • target : the desired currency (string).

Output

Return a single float: the maximum achievable conversion rate from source to target, or -1.0 if no conversion path exists. Answers within 1e-6 relative or absolute tolerance are accepted.

Example

pairs  = [["USD", "EUR", 0.9],
          ["EUR", "GBP", 0.85],
          ["USD", "GBP", 0.7],
          ["GBP", "JPY", 190.0]]
source = "USD"
target = "JPY"

Output:

145.35

Explanation: the path USD -> EUR -> GBP -> JPY gives 0.9 * 0.85 * 190.0 = 145.35, which beats the direct-ish alternative USD -> GBP -> JPY = 0.7 * 190.0 = 133.0.

Constraints

  • 1 <= N <= 200
  • Number of distinct currencies <= 14
  • Currency codes are non-empty strings of up to 10 uppercase letters
  • 0 < rate <= 10.0
  • The final answer is guaranteed to fit in a standard 64-bit floating-point value (it will not exceed 1e9 )
  • source and target are guaranteed to appear in at least one pair

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Optiver•More Software Engineer•Optiver Software Engineer•Optiver Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.