Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Array Summation and Currency Recognition

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Array Summation and Currency Recognition. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

WePay's Checkout surfaces can receive payment amounts written with either currency symbols or ISO currency codes. Given an array of valid payment strings, recognize each currency and return the total for every currency.

Amounts use at most two decimal places. Do not use floating-point arithmetic because exact totals are required. Store each total in the currency's smallest represented unit, where 12.50 becomes 1250.

Formal Specification

Implement aggregate_currency_payments(payments).

  • Input: payments, a list of strings. Each string is either a supported symbol followed immediately by an amount, such as "\$12.50", or an ISO code followed by one space and an amount, such as "EUR 7.5".
  • Output: A dictionary mapping each recognized currency code to its total in hundredths of that currency unit.
  • Supported currencies are USD ($), EUR (€), GBP (£), and JPY (¥).
  • Every input string is valid, and currencies with no payments do not appear in the result.

Constraints

  • 0 <= len(payments) <= 10^5
  • Amounts are nonnegative and less than 10^9
  • Amounts contain zero, one, or two digits after the decimal point
  • Currency codes are uppercase and belong to the supported set
  • Every input string follows one of the specified valid formats

Function Signature

def aggregate_currency_payments(payments):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output