FastPrepFour-Level Banking System with Scheduled Payments

Four-Level Banking System with Scheduled Payments

ZipRecruiter logoZipRecruiter● HardNEW GRADOA
Learn

Problem statement

Process strictly increasing timestamped string queries. Before each query, execute due scheduled payments by due time then creation order.

  • CREATE_ACCOUNT,t,id, DEPOSIT,t,id,amount, and TRANSFER,t,source,target,amount.
  • TOP_SPENDERS,t,n ranks active accounts by outgoing total descending then ID ascending, formatted id(total).
  • SCHEDULE_PAYMENT,t,id,amount,delay returns a global payment ID; a due payment debits and counts as outgoing only when funds suffice. CANCEL_PAYMENT,t,id,payment cancels an owned pending payment.
  • MERGE_ACCOUNTS,t,first,second absorbs second into first, carrying balance, outgoing total, pending payments, and history.
  • GET_BALANCE,t,id,timeAt returns the latest balance at or before timeAt, or empty when unavailable.

Return one serialized string per query; invalid numeric operations return empty, and booleans use lowercase.

Function

processBankingQueries(queries: String[][]) → String[]

Examples

Example 1

queries = [["CREATE_ACCOUNT","1","a"],["DEPOSIT","2","a","100"],["SCHEDULE_PAYMENT","3","a","30","5"],["GET_BALANCE","4","a","2"],["DEPOSIT","8","a","1"]]return = ["true","100","payment1","100","71"]

The payment executes at timestamp 8 before the deposit.

Example 2

queries = [["CREATE_ACCOUNT","1","a"],["CREATE_ACCOUNT","2","b"],["DEPOSIT","3","a","50"],["TRANSFER","4","a","b","20"],["TOP_SPENDERS","5","2"]]return = ["true","true","50","30","a(20),b(0)"]

The transfer contributes 20 outgoing for a.

Constraints

  • 1 <= queries.length <= 500
  • Timestamps are unique and strictly increasing.
  • Amounts and delays are positive.

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String[] processBankingQueries(String[][] queries) {
    // Write your code here.
}
queries[["CREATE_ACCOUNT","1","a"],["DEPOSIT","2","a","100"],["SCHEDULE_PAYMENT","3","a","30","5"],["GET_BALANCE","4","a","2"],["DEPOSIT","8","a","1"]]
expected["true", "100", "payment1", "100", "71"]
Checking account…