Software Engineer - 2 (ONSITE)
Anonymous User
1510

You are implementing a transaction handler that processes a list of money movements across multiple currencies.

Each transaction has:
• type: PAYIN or PAYOUT
• currency: a single currency code
• amount: a positive number

You are also given a currency conversion fee map. The map specifies the fee charged when converting funds from one currency into another.

For PAYOUT transactions only, the system may need to convert from available balances in other currencies so the payout can be completed while charging the minimum possible total conversion fee. If the payout cannot be completed with the funds available at that moment, return -1 for that payout.

Inputs

  1. Conversion fee map (fee for converting FROM -> TO):
{
  "AAA": { "BBB": 1.2, "CCC": 1.5 },
  "BBB": { "AAA": 1.1, "CCC": 1.4 },
  "CCC": { "AAA": 1.3, "BBB": 1.25 }
}
  1. Transactions (in given order):
[
  { "type": "PAYIN",  "currency": "AAA", "amount": 100 },
  { "type": "PAYIN",  "currency": "BBB", "amount": 50  },
  { "type": "PAYOUT", "currency": "CCC", "amount": 60  },
  { "type": "PAYOUT", "currency": "AAA", "amount": 30  }
]

⸻

Output

Return an array of the same length as transactions.

For each transaction:
• If PAYIN → output 0
• If PAYOUT → output the minimum conversion fee required to complete it, or -1 if it cannot be completed

Example output shape:

[0, 0, <min_fee_for_txn_3>, <min_fee_for_txn_4>]

⸻

Notes
• Only PAYOUT may require currency conversion.
• Assume you maintain balances as you process the list in order.
• The goal is to compute the minimum conversion fee per PAYOUT, given balances available at that point.

Comments (2)