FastPrepProgressive Banking Service Operations

Progressive Banking Service Operations

Valon logoValon● HardFULLTIMEONSITE INTERVIEW
Learn

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 amount credits the amount.
  • WITHDRAW t account amount debits available funds or fails without mutation.
  • TRANSFER t from to amount performs an instant internal transfer or fails without mutation.
  • EXTERNAL_OUT t account amount debits amount + 1 cents, including the one-cent fee, or fails.
  • EXTERNAL_IN t account amount credits amount - 1 cents after the one-cent fee; the amount is at least one.
  • SLOW_INIT t transferId from to amount reserves funds by removing them from the source available balance. It fails for a duplicate ID or insufficient funds.
  • SLOW_COMPLETE t transferId credits the reserved funds to the destination and removes the pending transfer, or returns NOT_FOUND.
  • BALANCE t account returns the available balance.
  • STATEMENT t account returns all mutation records for that account, joined with commas. Each record is timestamp: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.

More Valon problems

See Valon hiring insights
public String[] processBankingOperations(String[][] operations) {
    // Write your code here.
}
operations[["DEPOSIT","1","a","100"],["WITHDRAW","2","a","30"],["TRANSFER","3","a","b","50"],["BALANCE","4","a"],["BALANCE","5","b"]]
expected["OK|100", "OK|70", "OK|20|50", "20", "50"]
Checking account…