DoorDash logoDoorDash
Coding·60 minFree preview

Code Craft: Dasher Pay

The canonical DoorDash Code Craft prompt. Given a chronological event stream for a dasher's day (orders ACCEPTED / FULFILLED / CANCELED with timestamps), compute the dasher's total pay. Pay accrues per minute that the dasher has at least one ongoing delivery; multiple concurrent orders typically multiply the per-minute rate. Production-style follow-ups dominate the second half of the round.

SWE
EM
simulation
interval
state-machine
json
medium
Frequency
Very high
Last asked
2026-11-04
Stage
phone-screen · onsite-coding

Problem

  • Input: a chronological list of events for a single dasher. Each event is roughly {order_id, dasher_id, timestamp, status} where status is one of ACCEPTED, FULFILLED, CANCELED. Exact input shape (JSON object, list of tuples, timestamp as int vs ISO-8601 string) is deliberately left for the candidate to clarify with the interviewer — this is part of the signal. Use a clean dataclass / struct.
  • Output: the dasher's total pay for the day. Two flavors:
    • Basic: pay = number of minutes the dasher has ≥1 ongoing delivery × base_rate (often $0.30 / min). Some variants multiply by the count of ongoing deliveries (so 3 active orders for 1 minute = 3 × base_rate).
    • Peak-hour variant: a peak window (e.g. 17:00–19:00) doubles the per-minute rate. Intervals that straddle the boundary must be cut at the boundary, not double-counted.
  • Edge cases: a single order can be ACCEPTED then CANCELED with no FULFILLED. CANCELED closes the order's active window the same way FULFILLED does; clarify with the interviewer whether the minutes between ACCEPTED and CANCELED are paid before coding, since the two readings give different totals.
  • The follow-up the interviewer almost always asks: how do you turn this from a batch script into a service called by an upstream system? This is where the production discussion under Follow-ups comes from.
  • Test cases are usually supplied; after the implementation passes them, expect to modify them yourself to exercise edge cases.

Variants

Active-time-only variant

  • Given one day of timestamped pickup / dropoff actions, calculate the dasher's total active time. Idle time is time with no delivery in hand; active time is total time minus idle time.
  • This version returns elapsed active time rather than a dollar payout. Overlapping deliveries keep the dasher active without multiplying elapsed time.

Examples

The active-time-only version supplies this event sequence:

  • 8:30am: pickup
  • 9:10am: dropoff
  • 10:20am: pickup
  • 12:15pm: pickup
  • 12:45pm: dropoff
  • 2:25pm: dropoff

Multi-part progression with store-wait states

A multi-part progression shows up in some loops: Part 1 is the basic per-minute accrual; Part 2 adds ARRIVED and PICKED_UP states so that time the dasher spends waiting at the restaurant is not billed against the other concurrent orders; Part 3 layers on peak-hour double pay. Model each order's lifecycle explicitly so the wait-at-store window is attributed to the right order.

Minimal no-scaffold variant

  • A Q3 2026 basic version removes the peak-pay window and uses the saved time for production follow-ups, especially downstream-service failure handling.
  • No starter code is provided in this version. Java candidates must create the entry point, domain classes, and a small print-based test harness themselves.
  • Starter-test coverage varies: one Q3 2026 version supplied only a few simple inputs, while a newer minimal-scaffold interview supplied no test cases at all. Budget time to author targeted happy-path and edge-case checks, and verify expected outputs aloud before coding against them.

Pre-sorted peak windows as a separate list

In one recent version, the peak windows arrive as a separate list, and both the events and the peak windows are already sorted. The interviewer explicitly disallowed concatenating the two lists and re-sorting. Plan the merge of two pre-sorted sequences (a two-pointer walk, or binary-searching each peak boundary into the event timeline) before writing code.

Pitfalls

  • Common subtle bug: applying the multiplier change at the same instant as a status event without ordering them — break ties by processing event status changes after the time-based accounting for that timestamp.
  • Checking every event timestamp against every peak window is easy to start but hard to finish correctly under time pressure; the boundary that falls between two events still has to split that interval into normal-rate and peak-rate segments.
  • Timestamps as strings ("2025-12-03 13:15:00") come up in some variants; have a datetime.strptime / dateutil.parser.isoparse snippet ready or be willing to Google it in the editor — the interviewer typically allows this.
  • Java solutions run long because of Map<String, Order> boilerplate; Python is faster to finish bug-free.

Interviewer behavior

  • Aggressive clarification can legitimately shrink the problem: one phone screen collapsed Part 1 to a simple counter-based solution the interviewer accepted, and the saved time turned into a system-design-flavored conversation. Ask your scoping questions before writing code.
  • Expect pressure toward the sweep-line solution even when the recruiter frames the round as "workable solution first, optimize later." A simpler Part 1 can be accepted on paper and then sent back for a rewrite, which burns the time budget for Part 2.
  • Between Part 1 and Part 2 the interviewer may pause for an edge-case discussion and system-design-style questions (for example, what happens when the payment service is unavailable, or how to handle duplicate events from upstream) before introducing peak windows.

Follow-ups

Preparation

  • Implement the active-time-only scan separately in 10 minutes, returning minutes instead of dollars. Check empty input, overlapping deliveries, and a dropoff followed by a pickup at the same timestamp; compare the result with the union of the delivery intervals.
  • Write the basic implementation cold in under 25 minutes (sweep on event stream, maintain active_count, accumulate pay). Time yourself.
  • Write the peak-hour variant on top of the basic one in another 10 minutes; practice the boundary-split logic, then explain the prefix-sum alternative for the overlap lookup.
  • Pre-write 3 test cases: (1) one order start-to-finish; (2) three overlapping orders spanning a peak boundary; (3) an ACCEPTED with no FULFILLED before end-of-day. Walking through these test cases out loud is part of the graded signal.
  • Memorize 60-second answers for each production follow-up in the list above.
  • Pair-program the problem once with a friend acting as a hostile interviewer who interrupts to ask "why this data structure" mid-implementation; this is exactly the round's failure mode.
Was this article helpful?

Comments

Sign in to join the discussion
Loading...