Account Ledger
Asked at Airbnb
Reported by the problem's creator, not verified
You are building the transaction history of one bank account as the class AccountLedger. The balance starts at 0, and every call takes its time as a timestamp.
Examples
Example 1
Input: init =
[], operations =[["deposit",[1,100]],["deposit",[5,50]],["withdraw",[5,30]],["withdraw",[7,200]],["withdraw",[8,120]],["balance",[0]],["balance",[1]],["balance",[5]],["balance",[7]],["balance",[8]],["transaction_history",[1,5]],["transaction_history",[2,4]],["transaction_history",[6,8]],["transaction_history",[0,100]]]Output:
[null,null,true,false,true,0,100,120,120,0,[[1,100],[5,50],[5,-30]],[],[[8,-120]],[[1,100],[5,50],[5,-30],[8,-120]]]Explanation: Deposits of 100 (time 1) and 50 (time 5) and a withdrawal of 30 (time 5) leave 120. The withdrawal of 200 at time 7 is refused, since the balance is 120, and nothing is recorded. The withdrawal of 120 at time 8 empties the account and succeeds.
balance(5)counts all three entries at times 1 and 5.transaction_history(1, 5)includes the entries at both ends, in the order they were made.