Progressive Banking Service Operations
Problem statement
Process banking operations in strictly increasing timestamp order. Money values are integer cents. An account is created with zero available balance on first reference.
DEPOSIT t account amountcredits the amount.WITHDRAW t account amountdebits available funds or fails without mutation.TRANSFER t from to amountperforms an instant internal transfer or fails without mutation.EXTERNAL_OUT t account amountdebitsamount + 1cents, including the one-cent fee, or fails.EXTERNAL_IN t account amountcreditsamount - 1cents after the one-cent fee; the amount is at least one.SLOW_INIT t transferId from to amountreserves funds by removing them from the source available balance. It fails for a duplicate ID or insufficient funds.SLOW_COMPLETE t transferIdcredits the reserved funds to the destination and removes the pending transfer, or returnsNOT_FOUND.BALANCE t accountreturns the available balance.STATEMENT t accountreturns all mutation records for that account, joined with commas. Each record istimestamp:type:amount:status:resultingBalance.
Mutations return OK|balance or FAILED|balance. Instant transfers return OK|fromBalance|toBalance or FAILED|fromBalance|toBalance. Slow completion returns OK|destinationBalance or NOT_FOUND. Return one result per operation.
Function
processBankingOperations(operations: String[][]) → String[]Examples
Example 1
operations = [["DEPOSIT","1","a","100"],["WITHDRAW","2","a","30"],["TRANSFER","3","a","b","50"],["BALANCE","4","a"],["BALANCE","5","b"]]return = ["OK|100","OK|70","OK|20|50","20","50"]The deposit and withdrawal leave 70 cents, then the instant transfer moves 50 cents to b.
Example 2
operations = [["DEPOSIT","1","a","10"],["SLOW_INIT","2","x","a","b","8"],["BALANCE","3","a"],["SLOW_COMPLETE","4","x"],["STATEMENT","5","b"]]return = ["OK|10","OK|2","2","OK|8","4:SLOW_IN:8:SUCCESS:8"]Initiation removes the reserved funds from a. Completion credits b and records the incoming slow transfer.
Constraints
1 <= operations.length <= 10^5.- Timestamps are non-negative signed 64-bit integers and strictly increase.
- Amounts are positive and balances, amounts, and intermediate sums fit in signed 64-bit integers.
- Account and transfer IDs are non-empty and do not contain
:,|, or commas.