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
Transaction Processing Round
00:00
5 left

Transaction Processing Round

HardPython

Problem

Implement a processor for transactions on Highnote virtual card accounts. Each transaction must be applied atomically, rejected without partial changes when invalid, and safely ignored when its ID has already been processed.

A transaction is either a normal transaction containing one or more operations, or a reversal of one previously accepted transaction. Normal operations are deposit, withdraw, or transfer. Balances must never become negative. A reversal applies the exact inverse of the original transaction and may only occur once.

Formal Specification

Implement process_transactions(accounts, transactions), where accounts is a dictionary mapping account IDs to non-negative integer balances, and transactions is a list of transaction dictionaries. Each normal transaction has an id and an operations list. Each operation has type, account and amount, except transfers, which have from, to, and amount. A reversal has an id and reverse_of instead of operations.

Return {"accounts": updated_accounts, "results": results}. Each result contains the transaction ID and one status: accepted, rejected, or duplicate. Rejected transactions must not change any balance. Duplicate IDs must not be applied again.

Constraints

  • 1 <= len(accounts) <= 10^5
  • 1 <= len(transactions) <= 10^5
  • Each transaction has at most 10 operations
  • Account IDs and transaction IDs are non-empty strings
  • Amounts are positive integers at most 10^9
  • Balances fit within signed 64-bit integer range

Function Signature

def process_transactions(accounts, transactions):
Interviewer

Your question is Transaction Processing Round. 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.