ZipRecruiterOA #1
Banking System (4 Progressive Levels)
估计中等评测数据准备中,可先阅读题面
Implement a simplified version of a banking system. All operations have a timestamp parameter (stringified ms, range 1 to 10⁹, strictly increasing).
Level 1 — Account Creation, Deposit, Transfer
boolean createAccount(int timestamp, String accountId)— creates a new account. Returnstrueif successful,falseif account already exists.Optional<Integer> deposit(int timestamp, String accountId, int amount)— deposits given amount to specified account. Returns the balance after the operation. ReturnsOptional.empty()if account doesn't exist.Optional<Integer> transfer(int timestamp, String sourceAccountId, String targetAccountId, int amount)— transfer amount from source to target. Returns balance of source after the transfer, orOptional.empty()if either account doesn't exist, source == target, or source has insufficient funds.
Level 2 — Top Spenders by Outgoing Transactions
List<String> topSpenders(int timestamp, int n)— return the topnaccounts ordered by highest total money withdrawn from the account (outgoing transactions only —transfersource andpaycount). If two have the same total, order lexicographically by account id. Format:"accountId(amount)".
Level 3 — Scheduled Payments with Cashback
-
Optional<String> pay(int timestamp, String accountId, int amount)— withdraw given amount. All withdraw transactions provide a 2% cashback — 2% of the withdrawn amount (rounded down) will be refunded to the account 24 hours after the withdrawal. If the withdrawal is successful (i.e., the account has sufficient funds to perform the given amount), returns a unique payment identifier"payment{ordinal}"(e.g."payment1","payment2", etc.). Additional conditions: -
Returns
Optional.empty()if the account doesn't exist. -
Returns
Optional.empty()if the account has insufficient funds. -
topSpendersshould now also account for total amount of money withdrawn from accounts viapay. -
The waiting period for cashback is 24 hours, equal to
24 * 60 * 60 * 1000 = 86,400,000ms. -
When it's time to process cashback for a withdrawal, the amount must be refunded to the account before any other transactions are performed at the relevant timestamp.
-
Optional<String> getPaymentStatus(int timestamp, String accountId, String paymentId)— return the payment status. ReturnsOptional.empty()if the account doesn't exist, or the payment doesn't exist for the specified account. Otherwise return string representing the payment status:"IN_PROGRESS"or"CASHBACK_RECEIVED".
Level 4 — Account Merging with History
-
boolean mergeAccounts(int timestamp, String accountId1, String accountId2)— mergeaccountId2intoaccountId1. ReturnsfalseifaccountId1 == accountId2or any account doesn't exist. Returnstrueif accounts were successfully merged. Specifically: -
All pending cashback refunds for
accountId2should still be processed, but refunded toaccountId1instead. -
After the merge, it must be possible to check the status of payment identifiers belonging to
accountId2by replacingaccountId2withaccountId1. -
The balance of
accountId2should be added to the balance foraccountId1. -
topSpendersshould recognize merged accounts — total outgoing transactions for merged accounts should be the sum of all money transferred and/or withdrawn in both accounts. -
accountId2should be removed from the system after the merge. -
Optional<Integer> getBalance(int timestamp, String accountId, int timeAt)— return the total amount of money in the account at the given timestamptimeAt. If the specified account did not exist at a given timetimeAt, returnsOptional.empty(). -
If queries have been processed at timestamp
timeAt,getBalancemust reflect the account balance after the query has been processed. -
If the account was merged into another account, the merged account should inherit its balance history.