Practice/Capital One/Leetcode 2043. Simple Bank System
CodingMust
You need to implement a banking system that manages multiple customer accounts. The system should support three fundamental banking operations: transferring money between accounts, depositing money into an account, and withdrawing money from an account.
Your task is to create a Bank class that is initialized with an array of starting balances for each account. The accounts are numbered starting from 1 (not 0), so the first element in the balance array corresponds to account 1, the second element to account 2, and so on.
Each operation should validate that:
If an operation cannot be completed due to invalid account numbers or insufficient funds, it should return false without modifying any balances. Otherwise, it should perform the operation and return true.
transfer(account1, account2, money) method that moves money from account1 to account2deposit(account, money) method that adds money to the specified accountwithdraw(account, money) method that removes money from the specified accounttrue on success and false on failureExample 1:
` Input: Bank bank = new Bank([100, 200, 300]) bank.withdraw(1, 50) bank.deposit(2, 100) bank.transfer(3, 1, 150)
Output: [true, true, true]
Explanation:
Example 2:
` Input: Bank bank = new Bank([500, 1000]) bank.withdraw(3, 100) bank.deposit(2, 50) bank.transfer(2, 1, 2000)
Output: [false, true, false]
Explanation:
Example 3:
` Input: Bank bank = new Bank([100]) bank.withdraw(1, 100) bank.withdraw(1, 10)
Output: [true, false]
Explanation: