Banking System, Part 4: Merging and Balance History
Reported by candidates from Anthropic's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Anthropic reported this one in July 2026, and the detail that bites is in Example 1: secondary had balance 180 at timestamp 6, but GET_BALANCE at time 7 returns null because the merge killed it. This is Part 4 of a cumulative banking system, so it's a design problem, not an algorithm puzzle. You're stacking MERGE_ACCOUNTS and GET_BALANCE on top of accounts, transfers, top spenders and scheduled payments. If your Part 1-3 code is shaky, this part exposes it. StealthCoder is the safety net if you blank mid-OA, but the structure below should get you most of the way.
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 cumulative banking system from Parts 1 through 3. The system now merges accounts and answers historical balance queries. Operation Format Each input row contains an operation name followed by string arguments. Return one result row per operation. Scalar and null results use a one-element row; TOP_SPENDERS returns its list directly. Scheduled payments are processed before every input operation exactly as in Part 3. Level 4 Operations ["MERGE_ACCOUNTS", timestamp, account_id_1, account_id_2]: Merge Account 2 into Account 1. Return false if the IDs are equal or either active account does not exist; otherwise return true. On a successful merge, add Account 2's balance and outgoing total to Account 1. Move every pending payment owned by Account 2 to Account 1. It can then be canceled using Account 1's ID. Remove Account 2 from the active system after the merge. ["GET_BALANCE", timestamp, account_id, time_at]: Return that ID's balance immediately after all operations and scheduled-payment activity at time_at. Return null if the account did not exist at that time. Conservative History Scope The history rules below are the only merge-history behavior judged in this part: Before a merge, each account ID has its own balance history. At the merge timestamp, Account 1's balance becomes the combined balance and Account 2 stops existing. Account 2's balance before the merge remains queryable using Account 2 and an earlier time_at. From the merge timestamp onward, Account 1's history reflects the combined account. No additional behavior from the unavailable remainder of the source is assumed. Function bankingSystemLevel4(operations: String[][]) → String[][] Examples Example 1 operations = [["CREATE_ACCOUNT","1","primary"],["CREATE_ACCOUNT","2","secondary"],["DEPOSIT","3","primary","100"],["DEPOSIT","4","secondary","200"],["SCHEDULE_PAYMENT","5","secondary","50","10"],["TRANSFER","6","secondary","primary","20"],["MERGE_ACCOUNTS","7","primary","secondary"],["TOP_SPENDERS","8","1"],["CANCEL_PAYMENT","9","primary","payment1"],["DEPOSIT","10","secondary","1"],["GET_BALANCE","11","primary","7"],["GET_BALANCE","12","secondary","6"],["GET_BALANCE","13","secondary","7"]] return = [["true"],["true"],["100"],["200"],["payment1"],["180"],["true"],["primary(20)"],["true"],["null"],["300"],["180"],["null"]] The merge combines balances 120 + 180 = 300, outgoing totals, and the pending payment. Secondary existed with balance 180 at timestamp 6, but no longer exists at timestamp 7. Example 2 operations = [["CREATE_ACCOUNT","1","a"],["CREATE_ACCOUNT","2","b"],["DEPOSIT","3","a","50"],["DEPOSIT","4","b","100"],["SCHEDULE_PAYMENT","5","b","70","5"],["MERGE_ACCOUNTS","6","a","b"],["DEPOSIT","10","a","10"],["GET_BALANCE","11","a","10"],["TOP_SPENDERS","12","1"],["CANCEL_PAYMENT","13","a","payment1"]] return = [["true"],["true"],["50"],["100"],["payment1"],["true"],["90"],["90"],["a(70)"],["false"]] The pending payment moves from B to A during the merge. It executes before the timestamp-10 deposit, reducing the combined balance from 150 to 80; the deposit then raises it to 90. Constraints 1 <= time_at <= timestamp <= 10^9 All input-operation timestamps are unique and strictly increasing. Amounts, delays, and ranking limits are positive integers. All numeric results and scheduled execution timestamps fit in a signed 64-bit integer. Every operation has exactly the arguments defined in Parts 1 through 4.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The pattern is design plus per-account history. Store each account's balance as a list of (timestamp, balance) snapshots, appended on every change. GET_BALANCE then becomes a binary search for the last snapshot at or before time_at, returning null if the account didn't exist yet or was merged away by then. On merge, record the combined balance on Account 1 at the merge timestamp, mark Account 2 as ended at that timestamp, add outgoing totals, and reassign every pending payment's owner to Account 1. The classic pitfall is ordering. Scheduled payments must run before each input operation, including the merge and the balance query. Example 2 shows a moved payment firing before a later deposit. Another trap is letting Account 2's old history vanish. Queries with an earlier time_at must still work. If the payment queue logic falls apart live, StealthCoder can cover you, but get the ordering right first.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Banking System, Part 4: Merging and Balance History 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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Anthropic's OA.
Anthropic reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Banking System, Part 4: Merging and Balance History FAQ
What's the trick in Anthropic's Banking System Part 4?+
Keep a timestamped balance history per account ID. GET_BALANCE binary searches for the last snapshot at or before time_at. Merging appends a combined snapshot to Account 1 and closes Account 2's existence window, so old queries on Account 2 still work.
How hard is this really?+
The logic isn't deep, but it's cumulative. Part 4 breaks if Parts 1-3 have bugs, especially scheduled payment processing. Expect the difficulty to come from state management and ordering, not from clever algorithms.
What happens to pending payments on a merge?+
Every pending payment owned by Account 2 moves to Account 1. It can then be canceled using Account 1's ID. Example 2 shows the moved payment executing later and reducing the combined balance before the next deposit.
When does GET_BALANCE return null?+
It returns null if the account didn't exist at time_at. That covers accounts not yet created and accounts already merged away. In Example 1, secondary returns 180 at time 6 but null at time 7.
How do I prepare in 48 hours?+
Write the full system from Part 1 up, in one file. Test both examples by hand. Focus on the order of operations: process due scheduled payments first, then run the input operation. Then practice the snapshot-and-binary-search history lookup until it's automatic.