Banking System

Asked at AirbnbOnline assessment

Reported by the problem's creator, not verified

You are building an in-memory banking system as the class BankingSystem. Every method takes the call's timestamp as its first argument.

Examples

  1. Example 1

    Input: init = [], operations = [["create_account",[1,"a"]],["create_account",[2,"a"]],["create_account",[3,"b"]],["deposit",[4,"a",100]],["deposit",[5,"z",5]],["transfer",[6,"a","b",30]],["transfer",[7,"a","a",1]],["transfer",[8,"a","z",1]],["transfer",[9,"z","a",1]],["transfer",[10,"b","a",31]],["transfer",[11,"b","a",30]],["deposit",[12,"b",1]],["transfer",[13,"a","b",100]]]

    Output: [true,false,true,100,null,70,null,null,null,null,0,1,0]

    Explanation: a and b are created; the second creation of a fails. After 100 is deposited into a, transferring 30 to b returns a's new balance, 70. A transfer to the same account, to or from an unknown account, or of more than the source holds returns null. b holds exactly 30, so moving 30 back succeeds and leaves 0, and a can then move its whole balance of 100.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.