3387. Maximize Amount After Two Days of Conversions
You are given a string
initialCurrency
, and you start with1.0
ofinitialCurrency
.You are also given four arrays with currency pairs (strings) and rates (real numbers):
pairs1[i] = [startCurrencyi, targetCurrencyi]
denotes that you can convert fromstartCurrencyi
totargetCurrencyi
at a rate ofrates1[i]
on day 1.pairs2[i] = [startCurrencyi, targetCurrencyi]
denotes that you can convert fromstartCurrencyi
totargetCurrencyi
at a rate ofrates2[i]
on day 2.- Also, each
targetCurrency
can be converted back to its correspondingstartCurrency
at a rate of1 / rate
.You can perform any number of conversions, including zero, using
rates1
on day 1, followed by any number of additional conversions, including zero, usingrates2
on day 2.Return the maximum amount of
initialCurrency
you can have after performing any number of conversions on both days in order.Note: Conversion rates are valid, and there will be no contradictions in the rates for either day. The rates for the days are independent of each other.
c++
1 | class Solution { |