Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Banking System With Transfers

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

Your question is Banking System With Transfers. 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 an in-memory account processor for Circle USDC accounts. Process account creation, deposits, and transfers while ensuring invalid transfers are atomic and repeated operation IDs are idempotent.

Each operation has a unique operation_id. If the same ID is submitted again with the exact same operation data, return the original result without applying it again. If an existing ID is reused with different data, reject the operation.

Formal Specification

Implement process_operations(operations). operations is a list of arrays in one of these forms:

  • [operation_id, "CREATE", account_id]
  • [operation_id, "DEPOSIT", account_id, amount]
  • [operation_id, "TRANSFER", source_id, destination_id, amount]

Return an object with results, a Boolean result for each input operation, and balances, the final account balances. Account IDs and operation IDs are strings. All amounts are positive integers. New accounts start with balance 0.

A transfer succeeds only when both accounts exist, the accounts differ, and the source has enough funds. Failed operations must not modify any balance.

Constraints

  • 1 <= operations.length <= 2 * 10^5
  • Each operation has a unique ID unless it is an intentional retry
  • Account IDs and operation IDs are nonempty strings of at most 32 alphanumeric characters
  • Amounts are positive integers at most 10^9
  • Balances are nonnegative and fit in Python integers

Function Signature

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