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.
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.
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.deposit has an account field.withdrawal has an account field.transfer has from and to fields.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.
def process_transactions(balances, transactions):