Problem bank

Problem 248 of 333HardCodingP248

Currency arbitrage across many currencies

  1. You are given an n×nn \times n matrix rates where rates[i][j] is how many units of currency jj you get for one unit of currency ii. Write a function that returns whether some cycle of conversions turns 1 unit of a currency into more than 1 unit of the same currency. State the complexity.

    Test it on three currencies USD, EUR, JPY with USD→EUR 0.9, EUR→JPY 160 and JPY→USD 0.0070. Fill each reverse rate with the reciprocal (EUR→USD is 1/0.91/0.9, and so on) and put 1 on the diagonal.