FastPrepMaximum Currency Conversion with Arbitrage
Problems/Maximum Currency Conversion with Arbitrage

Maximum Currency Conversion with Arbitrage

Google logoGoogle● HardINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The firsthand Google internship report gives directed currency rates and asks for the maximum amount you can end with over paths of several hops. It calls out cycles that give unlimited gain. We use parallel edge arrays, two special numbers, directed edges, and a result that is finite and safe against rounding.

Each directed conversion edge i means that one unit of sources[i] converts to rates[i] units of targets[i]. Edges are directed; no reverse conversion exists unless it is listed.

Starting with amount units of source, return the maximum amount of target obtainable by applying edges any number of times.

  • Return -1.0 when target is unreachable from source.
  • Return -2.0 when a multiplicative-gain cycle is reachable from source and can still reach target, so the obtainable amount is unbounded.
  • Otherwise return the finite maximum amount. Using zero edges is allowed, so converting a currency to itself returns amount unless an applicable gain cycle makes it unbounded.

Function

maximumConversion(sources: String[], targets: String[], rates: double[], source: String, target: String, amount: double) → double

Examples

Example 1

sources = ["USD","CAD","USD","GBP"]targets = ["CAD","JPY","GBP","JPY"]rates = [1.3,100.0,0.8,150.0]source = "USD"target = "JPY"amount = 10.0return = 1300.0

The USD-CAD-JPY route multiplies by 130, producing 1300. The USD-GBP-JPY route multiplies by 120.

Example 2

sources = ["A","B","B"]targets = ["B","A","C"]rates = [2.0,0.6,1.0]source = "A"target = "C"amount = 1.0return = -2.0

The cycle A-B-A multiplies the amount by 1.2. It is reachable from A and can exit through B-C, so the target amount is unbounded.

Example 3

sources = ["A"]targets = ["B"]rates = [2.0]source = "B"target = "A"amount = 5.0return = -1.0

The only edge points from A to B, so A is unreachable from B.

Constraints

  • 0 <= sources.length == targets.length == rates.length <= 5000
  • There are at most 300 distinct currency codes across the edges and query.
  • Each currency code contains 1 to 10 uppercase English letters.
  • 0 < rates[i] <= 1000000 and 0 < amount <= 1000000000.
  • Any directed cycle's product is either at most 1 or differs from 1 by at least 10^-9.
  • Every finite answer is representable by a double.

More Google Phone Screen questions

  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
  • Minimum Total Layover WaitPHONE SCREEN · Seen Nov 2026
  • Reach a Destination Through Scheduled FlightsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Minimum Travel Time with Flashing Traffic LightsPeopleStrong · OAPeopleStrong interview questions
  • Shortest Distance from All BuildingsWaymo · PHONE SCREENWaymo interview questions
  • Dynamic Broadcast TimesNetflix · PHONE SCREENNetflix interview questions
  • Shortest Path Around Moving ParadesZip · PHONE SCREENZip interview questions
  • Cheapest Flights Within K StopsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Shortest Word Chain Between Two WordsFanatics · PHONE SCREEN
  • Shortest Paths in a Nonnegative Directed GraphNation with NaMo · PHONE SCREEN
  • Dijkstra Shortest Paths in a Weighted Undirected GraphGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Unit Conversion Across Independent FamiliesApple · PHONE SCREENApple interview questions
  • Shortest Distances From an Adjacency MatrixBoston Consulting Group · PHONE SCREENBoston Consulting Group interview questions

Interview reports that mention this question

  • Google SWE Intern Onsite Questions: 16 Experiences (Part 2 of 3)

Google interview experiences

  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
  • Google AI Coding Interview and AI OA: 2 Experiences
  • Google SWE Intern Interview Results Timeline: 13 Experiences
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public double maximumConversion(String[] sources, String[] targets, double[] rates, String source, String target, double amount) {
        // Write your code here.
    }
}
Checking account…