CT055

Currency Arbitrage Detection

HardAcceptance: 0.0%

Given a table of currency exchange rates as a 2-D array, determine whether there is a possible arbitrage opportunity: a sequence of trades starting with amount X of any currency that ends with more than X of that currency. Input: first line n (number of currencies), then n lines each with n exchange rates (rate[i][j] = currency i to j). Output "true" or "false".

Example 1:

Input: 4 1 0.77 71.71 0.87 1.3 1 93.55 1.14 0.014 0.01 1 0.012 1.15 0.88 83.33 1
Output: true

Example 2:

Input: 2 1 1 1 1
Output: false

Constraints:

1 <= n <= 100 0 < rate[i][j] <= 10^6 rate[i][i] = 1.0

Tags:

graph bellman-ford negative-cycle
Loading...
Test Cases:No test cases
No test cases available.