General Instructions
Your task is to implement a simplified version of a banking system. Plan your design according to the level specifications below:
- Level 1: The banking system should support creating new accounts and depositing money into and withdrawing/paying money from accounts.
- Level 2: The banking system should support ranking accounts based on the total value of transactions.
- Level 3: The banking system should support scheduling transfers and checking the scheduled transfer status.
- Level 4: The banking system should support merging two accounts while retaining the balances and transaction histories of the original accounts.
To move to the next level, you should pass all the tests at the current level.
Note
All queries will have a timestamp parameter — a stringified timestamp in milliseconds. It is guaranteed that all timestamps are unique and are in a range from 1 to 10^9. Queries will be given in the order of strictly increasing timestamps.
Level 1
The banking system should support creating new accounts and depositing money into and withdrawing/paying money from accounts.
create_account(self, timestamp: int, account_id: str) -> bool
- Should create a new account with the given account_idif it doesn't already exist.
- Returns Trueif the account was successfully created orFalseif an account withaccount_idalready exists.
deposit(self, timestamp: int, account_id: str, amount: int) -> int | None
- Should deposit the given amountof money to the specified accountaccount_id.
- Returns the total amount of money in the account (balance) after processing the query.
- If the specified account does not exist, should return None.
pay(self, timestamp: int, account_id: str, amount: int) -> int | None
- Should withdraw the given amountof money from the specified account.
- Returns the amount of money in the account (balance) after processing the query.
- If the specified account does not exist, or if the account has insufficient funds to perform the withdrawal, should return None.
Level 2
The banking system should support ranking accounts based on the total value of transactions.
top_activity(self, timestamp: int, n: int) -> list[str]
- Should return the top naccounts with the highest total value of transactions sorted in descending order (in case of ties, sorted alphabetically byaccount_idin ascending order).
- The returned value should be a list of strings representing an array of accounts and transaction values in this format:["<account_id_1>(<transactions_value_1>)", ..., "<account_id_n>(<transactions_value_n>)"]
Notes:
- Total value of transactions is defined as the sum of all transactions for an account (regardless of how the transaction affects account balance), including the amount of money deposited, withdrawn, and/or successfully transferred.
- If less than naccounts exist in the system, return all active accounts.
Level 3
The banking system should allow scheduling payments and checking the status of scheduled payments.
transfer(self, timestamp: int, source_account_id: str, target_account_id: str, amount: int) -> str | None
- Should initiate a transfer between accounts. The given amountof money should be withdrawn from thesource_account_idand held until the transfer is accepted by thetarget_account_id, or until the transfer expires. The withheld money is added back to the source account’s balance if the transfer expires.
Returns:
- Noneif- source_account_id==- target_account_id
- Noneif either account does not exist
- Noneif source has insufficient funds
- Otherwise, a valid transfer string: "transfer<ordinal number of the transfer>"(e.g.,"transfer1","transfer2"...)
Transfer details:
- Expiration period = 24 hours = 86400000milliseconds
- Transfers count toward the total value of transactions for both accounts
- Transaction history is updated only when the transfer is accepted
accept_transfer(self, timestamp: int, account_id: str, transfer_id: str) -> bool
- Accepts the transfer with the given transfer_id.
- Returns Trueif successful,Falseif the transfer ID doesn’t exist, is already expired, or was already accepted.
Level 4
The banking system should support merging two accounts while retaining the original accounts' balances and transaction histories.
merge_accounts(self, timestamp: int, account_id_1: str, account_id_2: str) -> bool
- Should merge account_id_2intoaccount_id_1.
Returns:
- Trueif accounts are merged successfully,- Falseotherwise
- Falseif- account_id_1 == account_id_2
- Falseif either account doesn't exist
Additional rules:
- All outgoing transfers from account_id_2are canceled (same as expired).
- All outgoing transfers from account_id_1toaccount_id_2are canceled.
- Any other incoming transfers to account_id_2are redirected toaccount_id_1.
- The balance of account_id_1is increased by the balance ofaccount_id_2.
- The total value of transactions for the merged account equals the sum of all transactions for both accounts.
- account_id_2should be removed from the system.
get_balance(self, timestamp: int, account_id: str, time_at: int) -> int | None
- Should return the total amount of money in account_id(balance) at the given timestamptime_at.
- If the account did not exist at time_at, should returnNone.

我们长期稳定承接各大科技公司如META、TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

