1
# Runtime: 1834 ms (Top 5.30%) | Memory: 43.9 MB (Top 45.70%)
2
class Bank:
3

4
def __init__(self, bal: List[int]):
5
self.store = bal # storage list
6

7
def transfer(self, a1: int, a2: int, money: int) -> bool:
8
try:
9
# checking if both accounts exist. and if the transaction would be valid
10
if self.store[a1 - 1] >= money and self.store[a2 - 1] >= 0:
11
# performing the transaction
12
self.store[a1 - 1] -= money
13
self.store[a2 - 1] += money
14
return True
15
else:
16
# retrning false on invalid transaction
17
return False
18
except:
19
# returning false when accounts don't exist
20
return False
21

22
def deposit(self, ac: int, mn: int) -> bool:
23
try:
24
# if account exists performing transaction
25
self.store[ac - 1] += mn
26
return True
27
except:
28
# returning false when account doesn't exist
29
return False
30

31
def withdraw(self, ac: int, mn: int) -> bool:
32
try:
33
# checking if transaction is valid
34
if self.store[ac - 1] >= mn:
35
# performing the transaction
36
self.store[ac - 1] -= mn
37
return True
38
else:
39
# returning false in case on invalid transaction
40
return False
41
except:
42
# returning false when account doesn't exist
43
return False

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0