Meta OA Interview Problem: Simplified Banking System

18 Views
No Comments

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.

The following operations are supported:

create_account(timestamp: int, account_id: str) -> bool
Should create a new account with the given account_id.

deposit(timestamp: int, account_id: str, amount: int) -> int | None
Should deposit the given amount of money into the account.

pay(timestamp: int, account_id: str, amount: int) -> int | None
Should withdraw/pay the given amount of money from the account.

top_activity(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, sort alphabetically by account_id in ascending order. The returned value should be a list of strings in the format ["<account_id_1>(<transactions_value_1>)", ...].

transfer(timestamp: int, source_account_id: str, target_account_id: str, amount: int) -> str | None
Should initiate a transfer between accounts. The amount is withdrawn from the source account and held until accepted by the target account or until the transfer expires. The transfer expires after 24 hours, which is equal to 24 * 60 * 60 * 1000 = 86400000 milliseconds. A transfer expires at the beginning of the next millisecond after the expiration period ends.

accept_transfer(timestamp: int, account_id: str, transfer_id: str) -> bool
Should accept the transfer with the given transfer_id.

merge_accounts(timestamp: int, account_id_1: str, account_id_2: str) -> bool
Should merge account_id_2 into account_id_1.

get_balance(timestamp: int, account_id: str, time_at: int) -> int | None
Should return the total amount of money in account_id at the given time_at.

If the specified account did not exist at time_at, return None.

If a query has been processed at time_at, get_balance must reflect the account balance after the query has been processed.

This Meta OA problem is a staged banking-system design exercise focused on state management, transaction accounting, scheduled transfers, and account merging. A practical solution usually uses hash maps for live account lookup, event logs or timeline tracking for balance reconstruction, and a transaction-total field for ranking accounts in top_activity. Level 3 introduces pending transfers that must be frozen, accepted, or expired, while Level 4 requires merging balances and histories without losing transaction totals and while redirecting or canceling transfer states correctly. The get_balance query is especially subtle because it must reflect the account state after any operation at the same timestamp has been processed.

END
 0