Simple Bank System
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A bank has n accounts numbered 1 to n; the starting balance of account i is balance[i - 1]. Implement Bank(balance) with three operations, each returning true if it succeeded and false if it was rejected (a rejected operation changes nothing):
- transfer(account1, account2, money) moves money from account1 to account2.
- deposit(account, money) adds money to account.
- withdraw(account, money) removes money from account.
An operation is rejected if it names an account outside 1..n, or if it would take more money out of an account than that account currently holds. Transferring to the same account is allowed and leaves the balance unchanged when it succeeds.
Examples
Constraints
- 1 <= n == balance.length <= 10^5
- 0 <= balance[i] <= 10^12
- 1 <= money <= 10^12
- 1 <= account, account1, account2 <= 10^5
- At most 10^4 calls in total
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.