Banking Pending Transfer Acceptance
Learn this problemProblem statement
Implement a banking system that reserves outgoing transfers until the recipient accepts them.
Operation Format
Each row in operations contains an operation name followed by string arguments. Timestamps are strictly increasing. Return one row for every operation. Scalar results use one-element rows; TOP_ACTIVITY returns its ranked list directly.
Before processing an operation at timestamp t, expire every unaccepted transfer whose expiration timestamp is strictly less than t and refund its reserved amount to the sender.
Basic Operations
["CREATE_ACCOUNT", timestamp, account_id]: create a unique account with balance zero. Returntrueorfalse.["DEPOSIT", timestamp, account_id, amount]: add funds and return the new balance, ornullif the account does not exist.["PAY", timestamp, account_id, amount]: withdraw funds and return the new balance. Returnnullfor a missing account or insufficient funds.["TOP_ACTIVITY", timestamp, n]: rank up tonaccounts by total processed amount descending, then account ID ascending. Format entries asaccount_id(total). Deposits, successful payments, and both sides of accepted transfers count; merely creating or expiring a transfer does not.
Pending Transfers
["TRANSFER", timestamp, source_id, target_id, amount]: validate two different existing accounts and sufficient source funds. Reserve the amount immediately and return a globally increasing IDtransfer1,transfer2, and so on. Returnnullon failure.- A transfer's expiration timestamp is
timestamp + 86400000. It may still be accepted at that exact timestamp; a later operation expires it. ["ACCEPT_TRANSFER", timestamp, account_id, transfer_id]: returntrueonly whenaccount_idis the intended recipient and the transfer is still pending. Credit the recipient, finalize the reserved debit, and add the amount to both accounts' activity totals. Otherwise returnfalse.
Function
bankingPendingTransferAcceptance(operations: String[][]) → String[][]Examples
Example 1
operations = [["CREATE_ACCOUNT","1","alice"],["CREATE_ACCOUNT","2","bob"],["DEPOSIT","3","alice","500"],["TRANSFER","4","alice","bob","200"],["TOP_ACTIVITY","5","2"],["ACCEPT_TRANSFER","6","bob","transfer1"],["TOP_ACTIVITY","7","2"]]return = [["true"],["true"],["500"],["transfer1"],["alice(500)","bob(0)"],["true"],["alice(700)","bob(200)"]]The transfer reserves 200 but does not affect activity until Bob accepts it. Acceptance then records 200 for both participants.
Example 2
operations = [["CREATE_ACCOUNT","1","a"],["CREATE_ACCOUNT","2","b"],["DEPOSIT","3","a","100"],["TRANSFER","10","a","b","70"],["ACCEPT_TRANSFER","86400011","b","transfer1"],["PAY","86400012","a","20"]]return = [["true"],["true"],["100"],["transfer1"],["false"],["80"]]The acceptance occurs one millisecond after the expiration timestamp, so the transfer is refunded before the failed acceptance. Account A can then pay 20 from its restored balance of 100.
More Anthropic problems
- Banking System, Part 1: Accounts and TransfersOA · Seen Jul 2026
- Banking System, Part 2: Top SpendersOA · Seen Jul 2026
- Banking System, Part 3: Scheduled PaymentsOA · Seen Jul 2026
- Banking System, Part 4: Merging and Balance HistoryOA · Seen Jul 2026
- Convert Stack Samples to Trace EventsPHONE SCREEN · Seen Jul 2026
- Cloud Storage SystemOA · Seen Jun 2026
- Repair the Bootloader ProgramONSITE INTERVIEW · Seen Jun 2026
- Normalize a DNS Domain NameOA · Seen May 2026