PayPal's "Banking System Operations" interview question focuses on designing an efficient system to process a sequence of banking operations (deposits, withdrawals, transfers) while supporting queries for top-k balances or transactions, leveraging hash tables for fast lookups and heaps for priority-based retrieval.[1]
Design a BankingSystem class that handles operations on multiple bank accounts. It must support:
BankingSystem(int n): Initialize with capacity for n accounts.void deposit(int accountId, double amount): Add amount to accountId's balance.void withdraw(int accountId, double amount): Subtract amount if sufficient funds.void transfer(int fromId, int toId, double amount): Move amount between accounts.double[] topKAccounts(int k): Return balances of top k richest accounts, sorted descending.[7]Example 1: ` Input: ["BankingSystem","deposit","deposit","topKAccounts","withdraw","topKAccounts"] [[3],[1,50.0],[2,100.0],[1],[3,20.5],[2]]
Output: [null,null,null,[100.0,50.0],null,[100.0,29.5]] `
Example 2: ` Input: ["BankingSystem","transfer","deposit","topKAccounts"] [[2],[1,2,10.0],[2,15.0],[2]]
Output: [null,null,null,[25.0,10.0]] `