Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Transaction Processing Round

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

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

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output