Premium problem149. Convert Amounts via a Rate Lookup

Medium Locked

Given amounts (1-D float), codes (1-D int, one per amount), a sorted int array rate_keys and a parallel float array rate_values, return the amounts multiplied by their matching rate:

  • match each code against rate_keys to find its rate
  • any code absent from rate_keys yields np.nan

Input

amounts = [10. 20. 30.]
codes = [2 7 5]
rate_keys = [2 5 9]
rate_values = [1.5 2.  0.5]

Output

[15. nan 60.]

Premium problem

This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.

Implement solve(...)