FastPrepShortest Currency Conversion with Three-Decimal Rate
Problems/Shortest Currency Conversion with Three-Decimal Rate

Shortest Currency Conversion with Three-Decimal Rate

Maven Clinic logoMaven Clinic● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Maven Clinic report describes currency conversion edges, three-decimal precision, and picking the shortest reachable conversion path. Here, the edges are directed, ties follow a fixed rule, and you return both the path and the rate. Our version is about 90% the same as the reported question.

Each string in rates has the form from,to,rate and represents one directed conversion edge. Find a path from source to target that uses the fewest edges.

When several shortest paths exist, choose the lexicographically smallest complete currency sequence. Return the currencies on that path followed by the cumulative conversion factor formatted with exactly three digits after the decimal point. Return an empty array when the target is unreachable.

Function

shortestConversion(rates: String[], source: String, target: String) → String[]

Examples

Example 1

rates = ["CAD,USD,0.88","USD,JPY,2000"]source = "CAD"target = "JPY"return = ["CAD","USD","JPY","1760.000"]

The unique two-edge path multiplies 0.88 by 2000.

Example 2

rates = ["USD,JPY,2000","USD,EUR,0.90","EUR,JPY,1600"]source = "USD"target = "JPY"return = ["USD","JPY","2000.000"]

The direct conversion uses fewer edges than the route through EUR.

Example 3

rates = ["USD,CAD,1.25"]source = "USD"target = "USD"return = ["USD","1.000"]

A currency converts to itself without traversing an edge.

Constraints

  • 0 <= rates.length <= 100000.
  • Currency names are nonempty ASCII strings without commas.
  • Each rate is finite and strictly positive.
  • The same ordered currency pair appears at most once.

More Maven Clinic interview questions

  • Minimum Appointment Cancellations with a Required BreakPHONE SCREEN · Seen Jun 2026
  • Configurable Valid BracketsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2025
  • Meeting Rooms IIPHONE SCREEN · Seen Aug 2025
  • Possible BipartitionPHONE SCREEN · Seen Aug 2024
  • Paginate Provider Listings with Per-Page DiversityONSITE INTERVIEW · Seen Apr 2026
  • Longest Valid ParenthesesONSITE INTERVIEW · Seen Aug 2025

Similar questions at other companies

  • Linked Merchants Within Two HopsStripe · PHONE SCREEN
  • Shortest Word Chain Between Two WordsFanatics · PHONE SCREEN
  • Open the LockAmazon · PHONE SCREEN
  • Find Duplicate Files in a FilesystemHarvey · PHONE SCREEN · ONSITE INTERVIEW
  • Shortest Word Transformation SequenceReddit · PHONE SCREEN
  • Word LadderGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEW
  • Word Ladder IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEW
  • Shortest Path from Encoded Graph EdgesBitGo · OA
  • Word LadderGoogle · ONSITE INTERVIEW
  • Minimum Word Ladder LengthSalesforce · ONSITE INTERVIEW
See Maven Clinic hiring insights
Saved
class Solution {
    public String[] shortestConversion(String[] rates, String source, String target) {
        // Write your code here.
    }
}
Checking account…