HomeInterview QuestionsGiven a list of records with amounts and currencie…

Given a list of records with amounts and currencies, convert all USD amounts to EUR and add the converted amounts to each record.

🟡 Medium Coding Junior level
1Times asked
Jun 2026Last seen
Jun 2026First seen

💡 Model Answer

To solve this, iterate over each record, validate the amount, and perform the conversion only for USD entries. Use a conversion rate (e.g., 1 USD = 0.85 EUR). For each USD record, compute converted_amount = float(amount) * rate and store it in a new key, e.g., record['converted_amount'] = converted_amount. Skip records with missing or invalid amounts. The algorithm runs in O(n) time and O(1) extra space (ignoring the output). Example code:

python
rate = 0.85
for r in records:
    amt = r.get('amount')
    if r.get('currency') == 'USD' and isinstance(amt, str):
        try:
            val = float(amt)
            r['converted_amount'] = val * rate
        except ValueError:
            pass

This adds the converted amounts while preserving the original data.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.

Get Assisting AI — Starts at ₹500