Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Array Summation and Currency Recognition
00:00
5 left

Array Summation and Currency Recognition

MediumPython

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):
Interviewer

Your question is Array Summation and Currency Recognition. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.