Bank System, an old question.
Adding some details:
- Level 2 needs to output a string with the account info: {accountId}{amount paid out}.
- For level 3, both all-transfers and pending-transfers are better done with a map rather than a list, to save time.
Level 1 is just creating an account, and adding to / withdrawing from the balance. Level 2: count the top N users by total amount transferred out — the tricky part was that I created a new object myself, didn't put it in the same class, put it in a separate one instead, and kept getting errors saying it couldn't be found. The rewrite based on the new object also kept showing red squiggly lines. I tried to debug and figure out why it kept flagging red, and eventually when I ran it, it turned out the site was just glitching — it actually worked, but I'd already spent way too long on it early on. Level 3: added schedule payment and cancel. I ran out of time, so I only wrote the corner cases and that kind of thing. Schedule payment took a timestamp and a delay as input and was supposed to return a string, roughly concatenating the accounts in order; schedule payment also counts as a transfer out, so it needs to update the previous top-N-transferred-out users.
Bank System. This is an old question that's already come up on the forum before.
Level 1: implement the 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 as the sum of pay amounts. Maintain a min-heap of size N with a priority queue.
Level 3:
String transfer(timestamp, targetAccountId, amount) // returns transferId
boolean accept(timestamp, accountId, transferId)
When you transfer, you hold the money from the source account; when it's accepted, it actually moves to the target account. Canceling a transfer needs to reset/clear it.
Level 4: Merge Accounts
mergeCustomers(oldId, newId)
Merges two customers, and requires keeping each one's balance, transaction records, and so on.
Discussion
Loading comments…