Skip to content

Practice Maximize Amount After Two Days of Conversions

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3387
LeetCode Problem

Maximize Amount After Two Days of Conversions

Problem Statement

Start with 1 unit of initialCurrency. On day 1, currencies may be converted using pairs1 and rates1; on day 2, use pairs2 and rates2. A listed pair converts in its given direction at its rate and in the reverse direction at the reciprocal rate. Perform any number of conversions on each day, completing day 1 before day 2. Each day’s rates are consistent. Return the maximum amount of initialCurrency obtainable after both days.

Source: Maximize Amount After Two Days of Conversions on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
initialCurrency = "EUR", pairs1 = [["EUR","USD"],["USD","JPY"]], rates1 = [2.0,3.0], pairs2 = [["JPY","USD"],["USD","CHF"],["CHF","EUR"]], rates2 = [4.0,5.0,6.0]
Output
720.00000

# Example 2

Input
initialCurrency = "NGN", pairs1 = [["NGN","EUR"]] , rates1 = [9.0] , pairs2 = [["NGN","EUR"]] , rates2 = [6.0]
Output
1.50000

# Example 3

Input
initialCurrency = "USD", pairs1 = [["USD","EUR"]], rates1 = [1.0], pairs2 = [["EUR","JPY"]], rates2 = [10.0]
Output
1.00000

Constraints

1 <= initialCurrency.length <= 3
initialCurrency consists only of uppercase English letters.
1 <= n == pairs1.length <= 10
1 <= m == pairs2.length <= 10
pairs1[i] == [startCurrencyi, targetCurrencyi]
pairs2[i] == [startCurrencyi, targetCurrencyi]
1 <= startCurrencyi.length, targetCurrencyi.length <= 3
startCurrencyi and targetCurrencyi consist only of uppercase English letters.
rates1.length == n
rates2.length == m
1.0 <= rates1[i], rates2[i] <= 10.0
The input is generated such that there are no contradictions or cycles in the conversion graphs for either day.
The input is generated such that the output is at most 5 * 10^10.

Related LeetCode Problems

Practice more problems similar to Maximize Amount After Two Days of Conversions.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.