Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Simplified Banking Transaction System

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

Your question is Simplified Banking Transaction System. 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 transaction processor for a simplified Revolut ledger. Apply deposits, withdrawals, and transfers sequentially, accepting only transactions that satisfy all validation rules.

A transaction is accepted atomically: if any rule fails, balances must remain unchanged and its ID must not appear in the accepted list.

Formal Specification

Implement process_transactions(balances, transactions).

  • balances is a dictionary mapping account IDs to non-negative integer balances.
  • transactions is a list of dictionaries. Each transaction has a unique string id, a type, and a positive integer amount.
  • A deposit has an account field.
  • A withdrawal has an account field.
  • A transfer has from and to fields.
  • Return a dictionary with balances, containing the final balances, and accepted, containing accepted transaction IDs in processing order.

Reject a transaction when its type is unknown, an account does not exist, the amount is not positive, a withdrawal or transfer lacks sufficient funds, or a transfer uses the same account as both source and destination.

Constraints

  • 1 <= len(balances) <= 10^5
  • 0 <= len(transactions) <= 2 * 10^5
  • Account IDs and transaction IDs are unique strings
  • Balances and amounts fit in a signed 64-bit integer
  • Every transaction contains the fields required by its declared type

Function Signature

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