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
Credit Card Account Operations
00:00
5 left

Credit Card Account Operations

HardPython

Problem

Imagine that you're writing software for a credit card provider. Implement a program that will add new credit card accounts (Add), process charges (Charge) and credits (Credit) against them, validate card numbers (digits only, 12-16 chars; bonus: Luhn 10), and return card holder names in lexicographical order with their balance, or "error" if the card number is invalid.

Asked in the phone screen stage. Charges over limit are declined; credits may go negative; invalid cards are ignored. Reported follow-ups: validate card numbers with the Luhn algorithm.

Function

def process_transactions(transactions):

Input

transactions is a list of strings, each in one of these forms:

  • Add <name> <card_number> <limit>
  • Charge <name> <amount>
  • Credit <name> <amount>

Output

Return a list of strings in lexicographical order by card holder name. Each string must be "<name>: <balance>", or "error" if any card number is invalid.

Constraints

  • 1 <= transactions.length <= 10^4
  • Each transaction is one of: Add, Charge, Credit
  • Card numbers contain only digits when valid, and have length 12 to 16 inclusive
  • Amounts and limits are positive integers
  • Card holder names are unique identifiers in the input

Function Signature

def process_transactions(transactions):
Interviewer

Your question is Credit Card Account Operations. 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.