Stage 1 of 3: Pay for a shift
Background. A Dasher picks up orders and drives them to customers, often with several on board at once. The app logs a shift as events: the Dasher accepts an order, and later delivers it.
Implement shift_pay(events, rate_cents) in pay.py. It returns the Dasher's pay for the shift as an int of cents.
eventsis a list of(minute, order_id, kind)tuples sorted byminute:minuteis an int from 0 to 10^9,order_ida string,kindeither"accept"or"deliver".- An order accepted at minute
aand delivered at minutedis on board for thed - aminutes fromaup tod; minuteditself is not counted. - Each minute pays
rate_centsonce for every order on board in it: a minute withkorders on board earnsk * rate_cents.rate_centsis a positive int.
Example
events = [
(0, "A", "accept"),
(5, "B", "accept"),
(10, "A", "deliver"),
(20, "B", "deliver"),
]
shift_pay(events, 30) # -> 750
From minute 0 to 5 only A is on board (5 × 30), from 5 to 10 both are (5 × 60), from 10 to 20 only B (10 × 30): 150 + 300 + 300 = 750.
Notes
- Events of the same minute may be listed in any order, so an order accepted and delivered in one minute may show its delivery first. Such an order is on board for 0 minutes and pays nothing.
- Every order in the log is accepted once and delivered once, never at an earlier minute than its acceptance.
- An empty log pays 0.
- Logs can be long. Submit times sets of logs of up to 64,000 events each, spread over up to 640 million minutes, and each set must be paid within 2 seconds.
Done when Submit goes green.
Constraints
- Python 3.12+ standard library only
- Time limit: 10 seconds per test
- Minutes are ints from 0 to 10^9
- Editable:
pay.py - Read-only: all
tests/test_*.pyfiles
What comes after stage 1
The next stages open once the tests for the one before them pass. Each raises the bar, the way an interviewer does in the room.
- Stage 2: Busy hours pay double. Some minutes pay double; the log and the list of busy hours both arrive in order, and the pay must be worked out without reordering either.
- Stage 3: Pickups and cancellations. The log now follows each order to its end, and not every order earns the minutes it spent in the Dasher's hands.
The files you get
- Yours to edit: pay.py.
- Read-only: tests/__init__.py.
- Tests you can read and run: tests/test_part1.py. Hidden tests run on Submit.
The round: no AI, an assistant that only answers
DoorDash runs this round without AI. Here the closest format is answer-only: the assistant answers your questions and reviews your code when you ask, the way an interviewer would, and never writes a line of it. The interviewer asks about your decisions as you go, and the report states the format. You can switch to the agent format when you press Begin.
Frequently asked, briefly answered
Is Dasher Pay free?
Stage 1 is free with an account. The other 2 stages need Nyrion Pro.
Which company asks something like this?
DoorDash. It is modelled on DoorDash's coding round, which runs without AI. Based on candidates' reports of DoorDash interviews. Nyrion wrote this version, so the question you get may differ.
Do I bring my own AI tool?
No. The real round has no AI, so this one opens answer-only: an assistant that answers your questions and can't write code. You can switch to an agent that proposes changes when you press Begin.
What does the interviewer ask?
3 questions along the way about your own code, and one at the end about the whole session. A weak answer gets one follow up. The answers go into the report, which ends with a hire or no hire verdict.
Start the problem
Sign in and the problem opens where you left it. New here? An account takes a minute to create, and the first stage of this problem is free.
More like it: every practice problem, DoorDash's interviews, the AI coding interview guide.