Banking System, Part 2: Top Spenders
Learn this problemProblem statement
Banking System series
- Part 1: Accounts and Transfers
- Part 2: Top Spenders
- Part 3: Scheduled Payments
- Part 4: Merging and Balance History
Continue the banking system from Part 1. All Level 1 operations keep the same behavior, and the system now ranks accounts by total outgoing transactions.
Operation Format
Each row in operations contains an operation name followed by string arguments. Return one row per operation. Scalar and null results use a one-element row. TOP_SPENDERS returns its list directly as the result row.
Previous Operations
CREATE_ACCOUNT, DEPOSIT, and TRANSFER behave exactly as described in Part 1. Only successful transfers add their amount to the source account's outgoing total.
Level 2 Operation
["TOP_SPENDERS", timestamp, n]: Return up tonactive accounts with the highest total outgoing amount.- Sort by outgoing amount in descending order. Break ties by
account_idin ascending alphabetical order. - Format each result as
account_id(total_outgoing). - If fewer than
naccounts exist, return all existing accounts.
At this level, outgoing transactions come from successful transfers. Part 3 also counts successfully executed scheduled payments.
Function
bankingSystemLevel2(operations: String[][]) → String[][]Examples
Example 1
operations = [["CREATE_ACCOUNT","1","alice"],["CREATE_ACCOUNT","2","bob"],["CREATE_ACCOUNT","3","cara"],["DEPOSIT","4","alice","500"],["DEPOSIT","5","bob","500"],["DEPOSIT","6","cara","500"],["TRANSFER","7","alice","bob","100"],["TRANSFER","8","bob","cara","100"],["TOP_SPENDERS","9","2"],["TRANSFER","10","bob","alice","50"],["TOP_SPENDERS","11","3"]]return = [["true"],["true"],["true"],["500"],["500"],["500"],["400"],["500"],["alice(100)","bob(100)"],["450"],["bob(150)","alice(100)","cara(0)"]]Alice and Bob first tie at 100 outgoing, so Alice comes first alphabetically. Bob's next transfer raises his total to 150.
Example 2
operations = [["CREATE_ACCOUNT","1","zed"],["CREATE_ACCOUNT","2","amy"],["DEPOSIT","3","zed","20"],["TRANSFER","4","zed","amy","30"],["TOP_SPENDERS","5","5"],["TRANSFER","6","zed","amy","10"],["TOP_SPENDERS","7","5"]]return = [["true"],["true"],["20"],["null"],["amy(0)","zed(0)"],["10"],["zed(10)","amy(0)"]]The failed transfer does not count as outgoing. With both totals at zero, Amy comes first alphabetically. The later successful transfer gives Zed an outgoing total of 10.
Constraints
1 <= timestamp <= 10^9- All timestamps are unique and operations are provided in strictly increasing timestamp order.
nand all amounts are positive integers.- All numeric results fit in a signed 64-bit integer.
- Every operation has exactly the arguments defined in Parts 1 and 2.
More Anthropic problems
- Banking System, Part 1: Accounts and TransfersOA · 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
- Worker Management, Part 4: Double-Paid IntervalsOA · Seen May 2026