← 返回 instacart 的题目列表OA: Banking Account System
类型:qbank
A 90-minute, five-part CodeSignal OA that incrementally builds a banking-account service: create accounts, deposit and make payments, rank accounts by transaction activity, initialize and accept expiring transfers, then merge accounts. Template code is provided, every operation receives the current timestamp, and the invitation explicitly says full completion is not expected.
Requirements
Every operation receives the current timestamp. Template code is provided.
Implement account creation with createAccount(account_id) -> None.
Add deposit and payment operations while preserving each account's state and transaction amount.
Return the top N accounts by transaction activity.
Add expiring transfers in two steps:
initializeTransaction(account1, account2, amount) -> transaction_id | None creates a transfer and returns None when it cannot be initialized.
accept(transaction_id) accepts the transfer only if it has not expired.
The final part adds account merging; confirm the exact merge interface and semantics from the template and visible tests before coding.
Every new part must keep all earlier behavior working.
Notes
Model each account as {balance, activity}, where activity accumulates the amount of every successful transaction. Ranking and merging both read from this record, so keep it in one place.
topN is a sort by (-activity, account_id). Confirm the tie-break and output shape (id(activity) vs a structured array) from visible tests before locking the comparator.
Store transfers as {transaction_id: (source, target, amount, expire_ts)}. Clarify whether initializeTransaction holds the amount immediately or only validates; return None when an account is missing or the source balance cannot cover the transfer. accept succeeds only while the transfer is unexpired.
Process expirations lazily: at the start of every operation, refund and drop transfers with expire_ts <= timestamp before handling the request — the same pattern as scheduled deletion in other CodeSignal multi-level tasks.
For merging, combine balances and activity totals, and decide what happens to pending transfers that reference the merged-away account. A redirect map from old id to surviving id keeps earlier operations working.
The 90-minute window rewards shipping the early parts quickly; a regression in an earlier part costs more than an unfinished final part.
Preparation
Implement create/deposit/pay first and get their tests green before touching ranking.
Drill the lazy-expiry helper with tests for accept at t = expire - 1 and t = expire.
Rehearse an account merge on paper: balances, activity totals, and a pending transfer pointing at the merged-away account.
Read every visible test before coding; tie-breaks and output formats in this OA family are usually only discoverable there.