Banking System, Part 2: Top Spenders
Reported by candidates from Anthropic's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Anthropic reportedly asked this one in July 2026, and it's a multi-part Banking System design problem where Part 2 adds a TOP_SPENDERS ranking on top of accounts and transfers. It looks like a simple sort. It isn't, because one edge case quietly breaks the naive version: failed transfers must not count toward outgoing totals, and zero-spend accounts still show up. If you're taking this OA in the next day or two, know that the later parts build on your Part 1 state, so sloppy structure now costs you later. StealthCoder is the safety net if you blank during the live assessment.
The problem
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 to n active accounts with the highest total outgoing amount. Sort by outgoing amount in descending order. Break ties by account_id in ascending alphabetical order. Format each result as account_id(total_outgoing). If fewer than n accounts 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. n and 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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The pattern is a stateful design problem. Keep a map of account to balance and a second map of account to outgoing total. Update the outgoing total only inside the success branch of TRANSFER, after the balance and account checks pass. That's the pitfall: Example 2 shows a failed transfer of 30 from an account holding 20 leaving the total at 0. For TOP_SPENDERS, collect every account, sort by outgoing descending then account_id ascending, slice to n, and format as id(total). Include accounts with 0 outgoing, as cara(0) shows. Sorting on each query is fine unless you expect heavy query volume. Keep the code modular, because Part 3 adds scheduled payments that also feed the outgoing total, and Part 4 adds merging. If you freeze on the tie-break or the row format mid-assessment, StealthCoder can give you a working reference solution in real time without the proctor seeing it.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Banking System, Part 2: Top Spenders cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Anthropic's OA.
Anthropic reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Banking System, Part 2: Top Spenders FAQ
What's the trick in Banking System Part 2: Top Spenders?+
Only successful transfers add to the source account's outgoing total. Update it inside the success branch, after all validation passes. Then sort by total descending and account_id ascending. Most wrong answers either count failed transfers or forget the alphabetical tie-break.
Do accounts with zero outgoing show up in TOP_SPENDERS?+
Yes. Example 1 returns cara(0) when n is 3, and Example 2 returns amy(0) and zed(0) when both totals are zero. Every existing account is a candidate, so initialize its outgoing total to 0 at CREATE_ACCOUNT time.
How hard is this Anthropic OA question really?+
The algorithm is easy, just a map and a sort. The difficulty is state discipline and parsing string arguments into the right output rows. It's a multi-part series, so a clean Part 1 and Part 2 structure decides whether Parts 3 and 4 go smoothly.
Do I need a heap for top n?+
Not required. Sorting all accounts per query is simple and correct. A heap or sorted structure only matters if the query count is huge. Under time pressure, write the sort first and keep the comparator exactly right: higher total first, then lexicographically smaller id.
How do I prepare for this in 48 hours?+
Write a small bank class with create, deposit, and transfer, tracking balance and outgoing separately. Test the failed transfer and tie cases from the examples by hand. Keep the operation handlers separate so scheduled payments and merging can plug in later without a rewrite.