FastPrepSimulate an Idempotent Refund Service Flow
Problems/Simulate an Idempotent Refund Service Flow

Simulate an Idempotent Refund Service Flow

DoorDash logoDoorDash● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report establishes the task identity and central capability. This practice contract supplies only the portable interface, deterministic boundary rules, and output serialization needed for consistent execution.

Process operations for an order service and a refund service:

  • ["CREATE", orderId, amount] creates an order, or reports EXISTS.
  • ["REQUEST", refundId, orderId, amount] creates a PENDING refund when enough unreserved amount remains; otherwise it records REJECTED. Reusing a refund ID is idempotent and returns its current state.
  • ["PROCESS", refundId, "SUCCESS"|"FAIL"] settles or releases a pending reservation. Processing a terminal refund returns its current state.
  • ["STATUS", refundId] returns its state or UNKNOWN.
  • ["BALANCE", orderId] returns available, refunded, and reserved, or UNKNOWN.

Status lines are exactly ORDER id STATE or REFUND id STATE; balance lines are ORDER id available=A refunded=R reserved=P.

Function

simulateRefunds(operations: String[][]) → String[]

Examples

Example 1

operations = [["CREATE","o1","100"],["REQUEST","r1","o1","40"],["BALANCE","o1"],["PROCESS","r1","SUCCESS"],["BALANCE","o1"]]return = ["ORDER o1 CREATED","REFUND r1 PENDING","ORDER o1 available=60 refunded=0 reserved=40","REFUND r1 SUCCEEDED","ORDER o1 available=60 refunded=40 reserved=0"]

The pending refund reserves funds and success converts the reservation into refunded value.

Example 2

operations = [["REQUEST","r1","missing","10"],["STATUS","r1"]]return = ["REFUND r1 REJECTED","REFUND r1 REJECTED"]

A missing order creates a terminal rejected refund for idempotent retries.

Constraints

  • 1 <= operations.length <= 100000.
  • IDs are nonempty and contain no spaces.
  • CREATE amounts are nonnegative; REQUEST amounts parse as signed integers.
  • Every operation has the documented shape.

More DoorDash problems

  • Customer Bootstrap APIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Dasher Pay with Store Waits and Peak HoursPHONE SCREEN · Seen Nov 2026
  • Random Dasher Set OperationsONSITE INTERVIEW · Seen Nov 2026
All DoorDash interview questionsSee DoorDash hiring insights
Saved
class Solution {
    public String[] simulateRefunds(String[][] operations) {
      // write your code here
    }
}
Checking account…