FastPrepProcess List of Commands
Problems/Process List of Commands

Process List of Commands

Stripe logoStripe● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are building a tool that tracks payment transactions for merchant accounts and computes each account's final balance. A transaction is always in one of these states:

  • PENDING: the transaction is created and waiting to be processed.
  • IN_PROGRESS: the transaction is being processed.
  • DONE: the transaction is completed and its amount was added to the balance.
  • REFUNDED: the transaction was refunded and its amount was taken back out of the balance.

Core commands:

  • START <account_id> <initial_balance> [refund_limit]: creates a merchant account with the given balance. The refund limit is optional.
  • NEW <transaction_id> <account_id> <amount>: creates a transaction for the account with the given amount, in the PENDING state.
  • PROCESS <transaction_id>: moves a PENDING transaction to IN_PROGRESS.
  • COMPLETE <transaction_id>: moves an IN_PROGRESS transaction to DONE and adds its amount to the account's balance.

Extended commands:

  • MODIFY <transaction_id> <new_amount>: changes the amount of a PENDING transaction.
  • CANCEL <transaction_id>: moves an IN_PROGRESS transaction back to PENDING.
  • RETURN <transaction_id>: refunds a DONE transaction: its amount is subtracted from the account's balance and it becomes REFUNDED.

If a transaction is not in the state a command needs (for example, COMPLETE on a PENDING transaction), the command does nothing. A REFUNDED transaction never changes again.

Time-limited refunds:

  • Commands may start with a time, for example 8 COMPLETE txn1. Either every command has a time or none does.
  • If an account has a refund limit L, a RETURN at time t works only if t - c ≤ L, where c is the time of the COMPLETE command that made the transaction DONE. Otherwise the RETURN does nothing and the transaction stays DONE.
  • If an account has no refund limit, refunds are always allowed. A limit of 0 means no refunds are allowed (times strictly increase, so t - c is always at least 1).

Process the commands in order and return the final balance of every account as the string "<account_id> <balance>", sorted by account ID in dictionary order (compare the IDs character by character, so "account10" comes before "account2").

Complete the function processCommands in the editor.

processCommands has the following parameter:

  • String[] commands: the commands, in time order

The function returns a String[]: one "<account_id> <balance>" string per account, sorted by account ID.

Function

processCommands(commands: String[]) → String[]

Examples

Example 1

commands = ["START account1 0", "NEW txn1 account1 50", "PROCESS txn1", "COMPLETE txn1"]return = ["account1 50"]

The commands are processed as follows:

  1. START account1 0 initializes account1 with a balance of 0.
  2. NEW txn1 account1 50 creates txn1 with amount 50 in the PENDING state.
  3. PROCESS txn1 moves the transaction to IN_PROGRESS.
  4. COMPLETE txn1 moves the transaction to DONE and adds 50 to the account balance.

The final balance is 50.

Example 2

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:

  1. START account1 0 initializes account1 with a balance of 0.
  2. NEW txn1 account1 50 creates txn1 with amount 50 in the PENDING state.
  3. PROCESS txn1 moves the transaction to IN_PROGRESS.
  4. CANCEL txn1 moves the transaction back to PENDING.
  5. The second PROCESS txn1 moves the transaction to IN_PROGRESS again.
  6. COMPLETE txn1 moves the transaction to DONE and adds 50 to the balance.
  7. RETURN txn1 refunds the completed transaction and deducts 50.

The final balance is 0.

Example 3

commands = ["1 START account1 0 5", "2 NEW txn1 account1 100", "8 COMPLETE txn1", "11 RETURN txn1", "16 RETURN txn1"]return = ["account1 0"]

The commands are processed as follows:

  1. 1 START account1 0 5 initializes account1 with balance 0 and a refund limit of 5.
  2. 2 NEW txn1 account1 100 creates txn1 with amount 100 in the PENDING state.
  3. 8 COMPLETE txn1 has no effect because txn1 is still PENDING; COMPLETE only moves a transaction from IN_PROGRESS to DONE.
  4. 11 RETURN txn1 has no effect because only a DONE transaction can be refunded.
  5. 16 RETURN txn1 has no effect for the same reason.

No command changes the account balance, so the final balance is 0.

Constraints

  • 1 ≤ commands.length ≤ 1000
  • 1 ≤ commands[i].length ≤ 60
  • Each command has one of the seven forms above, optionally preceded by a time, with single spaces between parts.
  • Either every command starts with a time or none does. Times are integers from 1 to 109 and strictly increase from one command to the next.
  • If the commands have no times, no START command gives a refund limit.
  • Account IDs and transaction IDs have 1 to 10 characters, each a lowercase English letter or a digit.
  • Each account is started once. Every NEW uses a transaction ID not used before and an account created by an earlier START.
  • Every PROCESS, COMPLETE, MODIFY, CANCEL and RETURN names a transaction created by an earlier NEW.
  • 0 ≤ initial_balance ≤ 106
  • 1 ≤ amount, new_amount ≤ 106
  • 0 ≤ refund_limit ≤ 109
  • All numbers in commands are integers written in plain decimal form.

More Stripe interview questions

  • Asynchronous Event ProcessingOA · Seen Nov 2026
  • Business Account KYC Verification — Parts 1–5PHONE SCREEN · Seen Nov 2026
  • Merchant Matching, Parts 1–2: Shared Fields and Weighted ThresholdsPHONE SCREEN · Seen Nov 2026
  • Maximum Game Score with Fixed Forward JumpsOA · Seen Nov 2026
  • Parse Boolean Rule ExpressionsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Reliable LLM Call with Independent Retry BudgetsOA · Seen Nov 2026
  • Request Routing SystemOA · Seen Nov 2026
  • Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesPHONE SCREEN · Seen Nov 2026
  • Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesPHONE SCREEN · Seen Nov 2026
  • Financial Account LedgerOA · PHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Bank Accounts with Balance HistoryMeta · OAMeta interview questions
  • Corporate Card Expense RulesRippling · OA · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Least Recently Used CacheMicrosoft · OA · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • Parcel Event TrackingAirbnb · OAAirbnb interview questions
  • Process Banking OperationsVercel · OA
  • Expiring Authentication Token ManagerIBM · OAIBM interview questions
  • Layer History with Batch Undo and RedoFigma · OA · PHONE SCREENFigma interview questions
  • Event Statistics AggregatorWells Fargo · OAWells Fargo interview questions
  • Temporal Key-Field Database with Prefix ScansThe Trade Desk · OA
  • Per-Client Sliding-Window Rate LimiterGeneral Motors · OA

Interview reports that mention this question

  • Stripe OA: What It Tests (2026)

Stripe interview experiences

  • Stripe New Grad SWE OA and Phone Screen: 2 Experiences
  • Stripe Experienced SWE OA and Onsite Questions: 3 Experiences
  • Stripe SWE Intern Linked Merchants Team Screen: 1 Experience
  • Stripe SWE Onsite over Two Days: 1 Experience
  • Stripe New Grad SWE Phone Screen and Onsite: 2 Experiences
All Stripe interview questionsSee Stripe hiring insights
Saved
class Solution {
    public String[] processCommands(String[] commands) {
        // write your code here
    }

}
Checking account…