← 返回 coinbase 的题目列表Banking System Transactions
类型:online_judge
Design a simple banking transaction system with the following functionalities:
Users can create accounts, each with a unique ID and an initial balance.
Users can deposit and withdraw money; deposits increase the balance, withdrawals decrease it.
Users can perform transfers from one account to another; ensure that each transfer has a unique ID.
Requirements:
Implement the above functionalities with minimal space complexity.
Provide test cases to verify each function, such as account creation, deposit, withdrawal, and transfer.
Ensure safe operations in a concurrent environment.
Data limits:
Assume a maximum of 10^5 accounts.
Each account can have up to 10^4 operations.
Test cases:
Create 3 accounts, ID 1, 2, and 3, with balances of 100, 200, 300 respectively.
Deposit 50 into account 1 and verify the balance is 150.
Withdraw 100 from account 2 and verify the balance is 100.
Transfer 100 from account 3 to account 1, verify account 3's balance is 200 and account 1's balance is 250.
Example
Input
1
create_account(1, 100)
create_account(2, 100)
deposit(1, 50)
withdraw(2, 50)
transfer(1, 2, 50)