This is the old bank system question from the forum. Let me add some details.
Level 2 needs to output a string with the account information: {accountId}{amount spent}. For level 3, all transfers and pending transfers are best kept in a map rather than a list, to save time.
Level 1: just creating an account, and adding/deducting balance. Level 2: track the n users who transferred out the most money — the annoying part was that I created a new object and put it in a separate file instead of the same class, so it kept saying it couldn't find it, and the rewrite based on the new object kept showing red underlines too. I tried to debug it and figure out why it was underlining everything red, and later when I ran it I found out the site was just glitching — it could actually run fine, but I'd already burned too much time on it earlier. Level 3: add schedule payment and cancel — I ran out of time and only wrote something for the corner cases. Schedule payment took a timestamp and a delay as input and had to return a string, basically concatenating accounts in order; schedule payment also counts as a transfer out, so it needs to update the previous top-n-users-by-amount-transferred-out list. Bank System — this is an old question that's shown up on the forum before.
Level 1: implement createAccount, deposit, and pay methods.
class BankSystemImpl : BankSystem {
bool createAccount(timestamp, customerId)
Int deposit(timestamp, customerId, amount)
Int pay(timestamp, sourceAccountId, targetAccountId, amount)
}
Level 2: find the top N by pay amount, calculated by summing up pay amounts. A priority queue maintaining a min-heap of size N works.
Level 3: String transfer(timestamp, targetAccountId, amount) returns a transferId; boolean accept(timestamp, accountId, transferId). When transferring, hold the money from the source account; when accepted, actually move it to the target account. Cancelling a transfer needs to reset/clear it.
Level 4: Merge Accounts — mergeCustomers(oldId, newId), merging two customers while keeping each one's balance, transaction history, etc.
Discussion
Loading comments…