Progressive Banking System
Learn this problemProblem statement
Process queries in order. Each query contains an operation name followed by a strictly increasing non-negative timestamp and its arguments. Before processing an external query at timestamp t, execute every pending scheduled payment whose due time is at most t, ordered by due time and then payment creation order.
Return one string per external query, in order. Supported operations are:
["CREATE_ACCOUNT", t, account]: create an account with balance and outgoing total zero. Returntrue, orfalseif the active account already exists.["DEPOSIT", t, account, amount]: add a positive amount. Return the new balance, or the empty string when the account is absent.["TRANSFER", t, source, target, amount]: move a positive amount between two distinct active accounts. Return the source balance after success, or the empty string when either account is absent, the accounts are equal, or funds are insufficient. A successful transfer adds the amount to the source account's outgoing total.["TOP_SPENDERS", t, n]: among active accounts, return at mostnentries formattedaccount(outgoing), ordered by outgoing total descending and account identifier ascending, joined by commas.["SCHEDULE_PAYMENT", t, account, amount, delay]: schedule a positive payment for timet + delay, wheredelayis positive. If the account exists, return the next global identifierpaymentK; otherwise return the empty string and do not consume an identifier.["CANCEL_PAYMENT", t, account, paymentId]: cancel a pending payment only when it currently belongs to that active account. Returntrueon success andfalseotherwise. A payment due attis processed before this cancellation query.["MERGE_ACCOUNTS", t, survivor, absorbed]: merge two distinct active accounts. The survivor receives the absorbed balance and outgoing total; pending payments of the absorbed account now belong to the survivor; and the absorbed account closes att. Returntrueon success andfalseotherwise.["GET_BALANCE", t, account, timeAt]: return that account's balance immediately after all activity at timestamptimeAt, or after the latest earlier activity when none occurred exactly then. Return the empty string if the account did not exist at that time. The requested time satisfies0 <= timeAt <= t.
When a scheduled payment becomes due, deduct it only if its current account is active and has enough funds. A successful payment adds to outgoing total. Whether it succeeds or not, it is no longer pending. Balances and totals fit in signed 64-bit integers.
Function
processBankingQueries(queries: String[][]) → String[]Examples
Example 1
queries = [["CREATE_ACCOUNT","1","alice"],["CREATE_ACCOUNT","2","bob"],["DEPOSIT","3","alice","100"],["TRANSFER","4","alice","bob","30"],["TOP_SPENDERS","5","2"]]return = ["true","true","100","70","alice(30),bob(0)"]The transfer leaves alice with 70 and records 30 of outgoing activity, so she ranks before bob.
Example 2
queries = [["CREATE_ACCOUNT","1","a"],["DEPOSIT","2","a","50"],["SCHEDULE_PAYMENT","3","a","20","5"],["GET_BALANCE","7","a","7"],["GET_BALANCE","8","a","8"],["CANCEL_PAYMENT","9","a","payment1"]]return = ["true","50","payment1","50","30","false"]The payment is still pending at timestamp 7. It executes before the query at timestamp 8, so cancellation afterward fails.
Example 3
queries = [["CREATE_ACCOUNT","1","a"],["CREATE_ACCOUNT","2","b"],["DEPOSIT","3","a","10"],["DEPOSIT","4","b","25"],["SCHEDULE_PAYMENT","5","b","5","5"],["MERGE_ACCOUNTS","6","a","b"],["GET_BALANCE","7","b","5"],["GET_BALANCE","8","b","6"],["GET_BALANCE","10","a","10"]]return = ["true","true","10","25","payment1","true","25","","30"]Account b exists with balance 25 before the merge but is closed at timestamp 6. Its pending payment follows the survivor and reduces the combined balance from 35 to 30 at timestamp 10.
Constraints
1 <= queries.length <= 2 * 10^4.- External query timestamps are strictly increasing integers from
0through10^9. - Every query has exactly one valid operation shape described above.
- Account identifiers are non-empty printable ASCII strings without commas or parentheses.
- Amounts and delays are positive integers, and every arithmetic result fits in a signed 64-bit integer.
1 <= n <= 10^5forTOP_SPENDERS.
More Airbnb problems
- Recipe Management SystemOA · Seen Jul 2026
- Parcel Event TrackingOA · Seen Jul 2026
- Worker Management, Part 3: Promotions and SalaryOA · Seen Jul 2026
- Worker Management, Part 2: Top WorkersOA · Seen Jul 2026
- Nested List Iterator with RemovePHONE SCREEN · Seen Jul 2026
- Worker Management with Full-Shift Double PayOA · Seen Jul 2026
- Worker Management, Part 1: Office RegistrationOA · Seen Jul 2026
- Most Frequent Reduced DigitOA · Seen Jul 2026