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.
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.
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.
def process_transactions(accounts, transactions):