Meta system design OOD OA 真题 – level 4 – 一亩三分地 – 买它 – OA 代写

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_id if it doesn't already exist.
  • Returns True if the account was successfully created or False if an account with account_id already exists.
deposit(self, timestamp: int, account_id: str, amount: int) -> int | None
  • Should deposit the given amount of money to the specified account account_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 amount of 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 n accounts with the highest total value of transactions sorted in descending order (in case of ties, sorted alphabetically by account_id in 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 n accounts 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 amount of money should be withdrawn from the source_account_id and held until the transfer is accepted by the target_account_id, or until the transfer expires. The withheld money is added back to the source account’s balance if the transfer expires.

Returns:

  • None if source_account_id == target_account_id
  • None if either account does not exist
  • None if 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 = 86400000 milliseconds
  • 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 True if successful, False if 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_2 into account_id_1.

Returns:

  • True if accounts are merged successfully, False otherwise
  • False if account_id_1 == account_id_2
  • False if either account doesn't exist

Additional rules:

  • All outgoing transfers from account_id_2 are canceled (same as expired).
  • All outgoing transfers from account_id_1 to account_id_2 are canceled.
  • Any other incoming transfers to account_id_2 are redirected to account_id_1.
  • The balance of account_id_1 is increased by the balance of account_id_2.
  • The total value of transactions for the merged account equals the sum of all transactions for both accounts.
  • account_id_2 should 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 timestamp time_at.
  • If the account did not exist at time_at, should return None.

我们长期稳定承接各大科技公司如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.

Leave a Reply

Your email address will not be published. Required fields are marked *