The system simulates a transaction intent management tool to handle the process from initialization to completion and calculate the final balances of merchants' accounts. Transaction states include:
Core Features:
Extended Features:
Time-Limited Refunds:
- If no limit is set, refunds are allowed indefinitely.
- A limit of 0 means no refunds are allowed.
Task Objective:
Process a list of commands to manage transaction intents and output the final balances of all accounts.
Input Format:
A time-ordered list of commands.
Output Format:
A list of account balances in ascending order by account ID.
commands = ["START account1 0", "NEW txn1 account1 50", "PROCESS txn1", "COMPLETE txn1"] return = ["account1 50"]
The commands are processed as follows:
- START account1 0: Initializes account1 with a balance of 0.
- NEW txn1 account1 50: Creates a new transaction intent txn1 for account1 with an amount of 50 in PENDING state.
- PROCESS txn1: Moves txn1 to IN_PROGRESS state.
- COMPLETE txn1: Moves txn1 to DONE state and adds the amount to account1's balance, resulting in a final balance of 50.
commands = ["START account1 0", "NEW txn1 account1 50", "PROCESS txn1", "CANCEL txn1", "PROCESS txn1", "COMPLETE txn1", "RETURN txn1"] return = ["account1 0"]
The commands are processed as follows:
- START account1 0: Initializes account1 with a balance of 0.
- NEW txn1 account1 50: Creates a new transaction intent txn1 for account1 with an amount of 50 in PENDING state.
- PROCESS txn1: Moves txn1 to IN_PROGRESS state.
- CANCEL txn1: Reverts txn1 to PENDING state.
- PROCESS txn1: Moves txn1 back to IN_PROGRESS state.
- COMPLETE txn1: Moves txn1 to DONE state and adds the amount to account1's balance, resulting in a balance of 50.
- RETURN txn1: Processes a refund for txn1 and deducts the amount from account1's balance, resulting in a final balance of 0.
commands = ["1 START account1 0 5", "2 NEW txn1 account1 100", "8 COMPLETE txn1", "11 RETURN txn1", "16 RETURN txn1"] return = ["account1 100"]
The commands are processed as follows:
- 1 START account1 0 5: Initializes account1 with a balance of 0 and a refund limit of 5.
- 2 NEW txn1 account1 100: Creates a new transaction intent txn1 for account1 with an amount of 100 in PENDING state.
- 8 COMPLETE txn1: Moves txn1 to DONE state and adds the amount to account1's balance, resulting in a balance of 100.
- 11 RETURN txn1: Processes a refund for txn1 within the refund limit and deducts the amount from account1's balance, resulting in a balance of 0.
- 16 RETURN txn1: The refund is not processed because it is outside the refund limit, so the balance remains 100.
- Count Valid Bitwise PairsOA · Seen Jun 2026
- Request Routing SystemOA · Seen May 2026
- Email Log Processing, Grouping, and SortingOA · Seen May 2026
- Generate Available Time SlotsPHONE SCREEN · Seen Apr 2026
- Chat Billing CalculationSeen Mar 2026
- Card Range Obfuscation Part 2 (ML Eng :)Seen Nov 2024
- Card Range Obfuscation Part 3 (ML Eng :)Seen Nov 2024
- Card Range Obfuscation Part 4 (ML Eng :)Seen Nov 2024
public String[] processCommands(String[] commands) {
// write your code here
}