Reported September 2026
DoorDashdesign

Simulate an Idempotent Refund Service Flow

Reported by candidates from DoorDash's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live DoorDash OA. Under 2s to a working solution.
Founder's read

DoorDash reported this one in September 2026, and it's less an algorithm puzzle than a state machine in disguise. The refund service has orders, refunds, reservations and idempotent retries, all handled through one function. If your OA invite says "Simulate an Idempotent Refund Service Flow", expect a long spec and a lot of small output strings. The pattern is design with hash maps. The risk isn't difficulty. It's missing one rule in the statement and failing hidden tests. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but you can know the shape of this before you start.

The problem

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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Keep two hash maps: orders keyed by orderId, refunds keyed by refundId. An order stores total, refunded, and reserved. Available is total minus refunded minus reserved, and the statement's example shows available=60 after a 40 reservation on 100, so check what "available" means before you print it. A refund stores its orderId, amount, and state: PENDING, SUCCEEDED, FAILED, or REJECTED. REQUEST first checks whether the refundId exists and returns its current state if so. That's the idempotency. Then a missing order or insufficient unreserved amount creates a terminal REJECTED refund. Watch the signed amounts: REQUEST can be zero or negative, so decide how to handle that from the spec. PROCESS only acts on PENDING. SUCCESS moves reserved to refunded, FAIL releases the reservation. Any terminal refund just echoes its state. The pitfall is output wording, like CREATED versus EXISTS and SUCCEEDED versus SUCCESS. If you freeze on the spec, StealthCoder is the hedge during the live OA.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Simulate an Idempotent Refund Service Flow cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass DoorDash's OA.

DoorDash reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Simulate an Idempotent Refund Service Flow FAQ

What's the core trick in the DoorDash refund simulation?+

Two hash maps and a strict state machine. Orders track total, refunded, and reserved. Refunds track state and amount. Every operation first checks whether the ID already exists, because idempotent retries must return the current state instead of re-applying the change.

How hard is this problem really?+

Algorithmically it's easy, with O(1) per operation and up to 100000 operations. The difficulty is reading carefully. Many small rules and exact output strings mean one missed edge case fails hidden tests, so slow down on the spec.

What edge cases trip people up?+

A request against a missing order must create a stored REJECTED refund, so a later STATUS returns REJECTED, not UNKNOWN. Signed REQUEST amounts need explicit handling. PROCESS on a terminal refund must change nothing. Reusing a refund ID with different details still returns the stored state.

How should I structure the code?+

Write one function with a switch on the operation name, plus small helpers for formatting status and balance lines. Keep an Order object and a Refund object. Append one output string per operation that produces output, matching the documented formats exactly.

How do I prepare in 48 hours?+

Practice two or three design-style simulation problems where you parse command arrays and maintain hash map state. Focus on idempotency and reservation logic. Then reread this spec's examples and trace them by hand, since they define the exact output format.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with DoorDash.

OA at DoorDash?
Invisible during screen share
Get it