CoinbaseBanking System (Multi-Level OA)
Four-level CodeSignal OA: implement a small bank backend that grows from basic account operations to spending leaderboards, scheduled / cancellable payments, and account merges that preserve history. A current Cloud Compute Credits rotation keeps the leaderboard and merge/history spine but replaces scheduled outgoing payments with delayed compute-consumption rebates. The volume of code is the difficulty; each level is straightforward in isolation but few finish all four in 70 minutes without prior practice. The same family also runs as a 3–4-step onsite coding round that opens with payment scheduling (schedule / cancel / status / process-due) and moves on to account merge, retire, and resolve.
Problem
You need to build a banking system. It must handle creating accounts, transferring money, tracking spending, paying bills later, and merging accounts. This problem has four levels. Each level adds new features to the last one.
Every action gets a timestamp (current time in milliseconds). Time always moves forward. Sometimes, multiple things happen at the exact same time.
Level 1: The Basics
Write a BankSystem class. It should let you create accounts, put money in, and move money between accounts.
class BankSystem:
def __init__(self):
"""Start the banking system."""
pass
def create_account(self, timestamp: int, account_id: str) -> bool:
"""
Make a new account with $0.
Returns:
True if created.
False if that ID already exists.
"""
pass
def deposit(self, timestamp: int, account_id: str, amount: int) -> bool:
"""
Add money to an account.
Returns:
True if successful.
False if the account is missing.
"""
pass
def transfer(self, timestamp: int, source_id: str, target_id: str, amount: int) -> bool:
"""
Move money from one account to another.
Returns:
True if successful.
False if an account is missing, ids are the same, or money is too low.
"""
passLevel 2: Tracking Spending
Now, you must track how much money leaves each account. You also need a function to find the accounts that spent the most.
def top_spenders(self, timestamp: int, n: int) -> list:
"""
Get the top N accounts that sent the most money.
Returns:
A list of strings like "account_id(total_spent)".
Sort by amount (highest first).
If amounts are equal, sort by ID (alphabetical).
Note:
- Only successful transfers count as spending.
- Deposits do NOT count.
"""
passLevel 3: Future Payments
The system needs to handle scheduled payments. Users can set a payment to happen later (timestamp + delay). They can also cancel it before it happens.
def schedule_payment(self, timestamp: int, account_id: str, amount: int, delay: int) -> str:
"""
Plan a payment for the future.
Returns:
A unique ID like "payment1", "payment2".
Returns "" if account doesn't exist.
Rules:
- If the account doesn't have money when the payment is due, skip it.
- Successful payments count as spending (for top_spenders).
- If multiple payments are due at the same time, do the oldest one first.
"""
pass
def cancel_payment(self, timestamp: int, account_id: str, payment_id: str) -> bool:
"""
Stop a scheduled payment.
Returns:
True if cancelled.
False if it's too late, already cancelled, or doesn't belong to the account.
"""
passExecution Order
This is the most important rule:
- Old Tasks First: Before doing anything else (like a deposit or a new transfer), the system must check if any scheduled payments are due.
- Current Task: Perform the user's requested action.
This means you can't cancel a payment if it is due right now. It executes before the cancel command runs.
Level 4: Merging and History
Two new hard features:
- Merge: Combine two accounts. The old account is deleted, and its money moves to the new one.
- History: Check what an account's balance was at a specific time in the past.
def merge_accounts(self, timestamp: int, account_id1: str, account_id2: str) -> bool:
"""
Merge account_id2 into account_id1.
- Add acc2's balance to acc1.
- Move acc2's scheduled payments to acc1.
- Delete acc2.
"""
pass
def get_balance(self, timestamp: int, account_id: str, time_at: int) -> int:
"""
Find the balance of an account at a past time (time_at).
- If the account was deleted (merged), you can still check its balance
from BEFORE it was deleted.
- If the account didn't exist at that time, return -1.
"""
passTricky Cases
- Deleted Accounts: Even if
acc2is deleted, we keep its history.get_balanceshould still work for times whenacc2was alive. - Post-Merge Queries: If you ask for
acc2's balance after it was merged, return -1. - Moving Payments: If
acc2had a scheduled payment,acc1must now pay it.
Examples
Level 1
bank = BankSystem()
bank.create_account(1, "acc1") # True
bank.create_account(2, "acc2") # True
bank.create_account(3, "acc1") # False (already exists)
bank.deposit(4, "acc1", 1000) # True
bank.deposit(5, "acc3", 500) # False (acc3 does not exist)
bank.transfer(6, "acc1", "acc2", 300) # True (acc1 has 700, acc2 has 300)
bank.transfer(7, "acc1", "acc2", 800) # False (not enough money)
bank.transfer(8, "acc1", "acc1", 100) # False (cannot transfer to self)Level 2
bank = BankSystem()
# ... create accounts ...
bank.deposit(4, "acc1", 2000)
bank.deposit(5, "acc2", 1000)
bank.transfer(7, "acc1", "acc2", 500)
bank.transfer(8, "acc2", "acc3", 300)
bank.transfer(9, "acc1", "acc3", 200)
bank.top_spenders(10, 2)
# Result: ["acc1(700)", "acc2(300)"]
# acc1 sent 500 + 200 = 700 total.
# acc2 sent 300 total.Level 3
# ... setup acc1 with 1000 ...
# Schedule payment of 500, due at time 103
pid1 = bank.schedule_payment(3, "acc1", 500, 100)
# Cancel it way before it is due
bank.cancel_payment(50, "acc1", pid1) # True
# At time 103, nothing happens because it was cancelled.Level 4
bank.create_account(1, "acc1")
bank.deposit(3, "acc1", 1000)
# acc1 has 1000
bank.merge_accounts(6, "acc1", "acc2")
# Assume acc2 had 500. Now acc1 has 1500. acc2 is gone.
# Check acc2 history BEFORE the merge
bank.get_balance(7, "acc2", 5) # Returns 500 (correct)
# Check acc2 history AFTER the merge
bank.get_balance(8, "acc2", 6) # Returns -1 (it didn't exist)Variants
Cloud Compute Credits
The same four-level object-design family now appears with workspaces and compute credits instead of bank accounts and money. Timestamps are unique, arrive in strictly increasing order, and range from 1 to 1,000,000,000 milliseconds.
- Level 1: implement
createWorkspace(timestamp, workspaceId),topUp(timestamp, workspaceId, amount), andtransferCredits(timestamp, sourceWorkspaceId, targetWorkspaceId, amount). New workspaces start at zero. A transfer fails when either workspace is missing, the IDs match, or the source lacks credits; a successful transfer returns the source's remaining balance. - Level 2: implement
topConsumers(timestamp, n). Rank every active workspace by total outgoing credits descending, then by workspace ID ascending. Outgoing transfers count; incoming transfers and top-ups do not. Return entries asworkspaceId(totalOutgoing), including zero-outgoing workspaces when needed to fill the result. - Level 3: implement
consume(timestamp, workspaceId, amount)andgetChargeStatus(timestamp, workspaceId, chargeId). Each successful consumption creates the next global ID (charge1,charge2, ...), contributes to outgoing credits, and schedules a rebate offloor(amount * 2%)exactly 86,400,000 milliseconds later. Process every rebate due at or before a new operation's timestamp before executing that operation. Charge status isIN_PROGRESSbefore crediting andREBATE_RECEIVEDafterward; reject unknown charges or charges owned by another workspace. - Level 4: implement
mergeWorkspaces(timestamp, workspaceId1, workspaceId2)andgetCredits(timestamp, workspaceId, timeAt). A merge absorbs the second workspace's balance, outgoing total, charge history, and pending rebates into the first, then removes the second from active operations. Pending rebates must follow the surviving workspace. Historical queries return the balance after the latest operation at or beforetimeAt, remain valid for a merged-away workspace before its merge timestamp, and return empty before creation or at/after that workspace's merge. The surviving workspace's pre-merge history must not include the absorbed balance retroactively.
This variant replaces scheduled outgoing payments with delayed incoming rebates. Clarify which Level 3 rotation is active before coding; the leaderboard and merge/history scaffolding are shared, but the time-ordered event semantics differ.
Onsite Coding — Ledger / Bank System
The same family also runs as a 3–4-step onsite coding round framed as "design a ledger/bank system". Later steps stay hidden until the current one is done, and the step order differs from the OA:
- Step 1:
schedule_payment,cancel_payment,get_payment_status,process_due_payments— payment scheduling is the starting point, and due-payment processing is its own method. - Step 2: merge account, retire account, resolve account.
Clarify the exact contracts for retire and resolve with the interviewer before coding. Dictionaries plus a heap cover the core state; everything else is basic CRUD.
Pitfalls
- Level 2 is the time sink for Java candidates. A
PriorityQueuewith a customComparatoris the cleanest implementation but takes more lines than the Pythonsorted(items, key=...)equivalent. Pre-write a min-heap template if you are using Java. - Hidden test counts are small (~10 per level) and the grader is generous on partial credit. Several candidates report passing the loop with only 3 of 4 levels completed.
- A payment due at the same timestamp as a
cancel_paymentcall executes first, so the cancel fails — drain due payments before every operation. - The onsite version provides no ready-made tests — you write your own test cases as you go. The later steps are tight on time; finishing only the first two is a realistic outcome, so keep step 1 lean.
Follow-ups
Preparation
- Time-box Level 1 to ≤15 minutes so you have 55 minutes for the harder three. Most of Level 1 is boilerplate; pre-memorize the data-structure choice (Map of accountId → account object holding balance + spend + a list of scheduled paymentIds).
- Drill the Level 2 "top-N by counter" pattern in your interview language until it is muscle memory.
- Practice the level-3 scheduled-payment pattern with a heap of
(fireTime, seq, paymentId, accountId, amount)tuples and acancelledset. Break same-time ties on an integer creation counter, not the ID string —"payment10"sorts before"payment2". Solve it once cleanly, then re-solve it adding Level 4's merge on top. - Re-solve the Cloud Compute Credits rotation with a heap of
(rebateTime, chargeId, workspaceId, rebateAmount)tuples plus charge-owner and charge-status maps. Before every public operation, drain due rebates; explicitly test a rebate due at the operation timestamp and an amount whose 2% rebate must be rounded down. - Extend that implementation through a merge: redirect pending rebates and charge ownership, combine outgoing totals, and append the merge-time balance changes without rewriting older snapshots. Test historical queries before creation, immediately before the merge, at the merge timestamp, and afterward.
- Treat the level-4 merge as a rename / re-pointer exercise, not a rewrite — every data structure should already be keyed by account-id, so merging is updating those keys.
- For the onsite ledger rotation, re-solve the scheduling level as the first step with an explicit
process_due_paymentsmethod and aget_payment_statuslookup, writing your own test cases as you go.
