Amazon VO Interview Problem: Currency Conversion Function

15 Views
No Comments

Given a file of currency conversion rates, write a function that converts one currency to another.

Sample log file entries:

{"from":"USD", "to":"EUR", "rate":1.1}
{"from":"EUR", "to":"AUD", "rate":2.1}
{"from":"AUD", "to":"INR", "rate":109.1}
{"from":"INR", "to":"GBP", "rate":10.1}
{"from":"AUD", "to":"GBP", "rate":10.1}

This Amazon VO problem asks you to build a function that converts one currency into another using a file of exchange-rate records. A natural approach is to model currencies as nodes in a graph and conversion rates as directed edges, then use hash maps plus BFS or DFS to find a path from the source currency to the target currency and multiply the rates along the path. If a direct conversion exists, return it immediately; otherwise, compute the indirect conversion through intermediate currencies.

END
 0