Shortest Currency Conversion with Three-Decimal Rate
Reported by candidates from Maven Clinic's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Maven Clinic reportedly used this one in March 2026, and the input size is the first thing to read. Up to 100000 rate strings means you can't enumerate paths and compare them. This is a shortest-path problem on a directed graph with unweighted edges, so BFS is the engine. The twist is the tie-break: lexicographically smallest full currency sequence, then a product of rates printed to exactly three decimals. If you've got an invite and 48 hours, learn this shape now. StealthCoder is the safety net on the live OA if the tie-break logic slips away from you mid-assessment.
The problem
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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Edge count is the cost, so run BFS from source and record distance to every node. Then you need the lexicographically smallest path among the shortest. The clean way: BFS from the target on the reversed graph to get distance-to-target, then walk forward from source. At each step, among neighbors whose distance-to-target is exactly one less, pick the smallest name. That greedy walk yields the smallest sequence because all candidates have equal length. Multiply rates along the walk and format with three decimals. The pitfalls: source equals target returns the node plus 1.000 with no edges. Unreachable returns an empty array, not a one-element list. Sorting neighbor lists up front is fine, but don't compare whole paths per node. Parse with split on commas, and use double for the product. StealthCoder is the hedge on the live OA if you blank on the reverse-BFS trick, since it reads the prompt and hands you working code without the proctor seeing it.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Shortest Currency Conversion with Three-Decimal Rate cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Maven Clinic's OA.
Maven Clinic reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Shortest Currency Conversion with Three-Decimal Rate FAQ
What's the trick in the Maven Clinic currency conversion problem?+
Fewest edges means BFS, not Dijkstra. The lexicographic tie-break is the real trick. Compute distance to target using a reversed-graph BFS, then walk forward from source choosing the smallest neighbor that sits exactly one step closer to the target.
Why not just BFS forward and keep the smallest parent?+
Picking the smallest parent at each node doesn't guarantee the smallest whole sequence from the start. Lexicographic order is decided from the front of the path. Forward greedy with distance-to-target guarantees every choice stays on a shortest path and is smallest at the earliest position.
How do I format the result to three decimals?+
Multiply the rates as doubles along the chosen path, then format with a fixed three-digit formatter, like String.format("%.3f") in Java or an f-string with.3f in Python. Append that string as the last element of the returned array after the currency names.
What edge cases should I test before submitting?+
Source equals target returns the currency and 1.000. An unreachable target returns an empty array. A currency that appears only as a destination needs to exist in your map. Zero rates means an empty graph, so handle that without crashing.
How do I prepare for this in 48 hours?+
Write BFS on a directed graph with a hash map of lists, then add the reversed-graph distance pass and the greedy forward walk. Do it once cold. Practice parsing comma-separated strings too, since the input format is where quick mistakes happen.