Level 1 Accounts, deposits and transfers
Build BankingSystem. Every method takes a timestamp (an integer, in milliseconds) as its first argument. Timestamps strictly increase from one call to the next, across all methods. Account ids are non-empty strings, and amounts are positive integers.
create_account(timestamp, account_id) -> bool: open an account with balance 0. ReturnFalseif an account with that id already exists.deposit(timestamp, account_id, amount) -> int | None: addamountto the account and return its new balance. ReturnNoneif the account doesn't exist.transfer(timestamp, source_id, target_id, amount) -> int | None: moveamountfrom the source account to the target account and return the source's new balance. ReturnNone, changing nothing, if either account doesn't exist, the two ids are the same, or the source's balance is less thanamount.
bank = BankingSystem()
bank.create_account(1, "a") # True
bank.create_account(2, "b") # True
bank.create_account(3, "a") # False: "a" exists
bank.deposit(4, "a", 500) # 500
bank.deposit(5, "zz", 10) # None: no such account
bank.transfer(6, "a", "b", 200) # 300 (b now has 200)
bank.transfer(7, "b", "a", 201) # None: b has only 200
bank.transfer(8, "a", "a", 1) # None: same account
Constraints: up to 10^5 calls, amounts up to 10^9. Balances can pass 2^31, so use 64-bit integers in C++ and Java.
Later levels build on this code: payments that run later, merges, and balances at past times. Each level unlocks when the previous one passes.