A payments queue delivers at least once: after a timeout, the same message can arrive again. Each delivery is a dict {"request_id", "account", "amount"}, and request_id identifies the deposit, not the delivery. Two different deposits can have the same account and amount; they are both real.
Write apply_deposits(balances, processed_ids, deliveries):
- •
balances — a dict account -> balance (a missing account has balance 0); - •
processed_ids — the set of request ids applied by earlier runs; - •
deliveries — this batch, in arrival order.
Add each deposit's amount to its account exactly once. A request id that was already processed, earlier or in this batch, is skipped. If the same request id arrives with different contents, the first delivery wins.
Return a tuple (new_balances, new_processed_ids). Don't modify the inputs.
Python 3.13 in your browser — the standard library plus pandas and numpy; no pip installs.