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.
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.
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.
def process_operations(operations):