Skip to main content
All Questions

Given dasher activity timestamps, calculate the payout for the day based on the delivery-time formula.

Medium
Unlock detailed company stats for this questionUpgrade

You've joined a delivery company's payouts team. Each day, a Dasher's deliveries arrive as raw text lines from the dispatch log: a delivery ID, the time it was accepted, and the time it was fulfilled. Turn a day of those lines into the Dasher's payout in cents.

The lines are messy. Some are malformed, some are duplicated, and some cross midnight. One bad line must not stop the whole day's payout, and one duplicated line must not pay twice.

Starter code and solution
Python 3.11+ (standard library)
Download code

What's in the codebase

  • payout.py. The pay constants and a stubbed calculate_payout(lines). The docstring is the full spec. This is the only file you change.
  • test_payout.py. Nineteen tests covering each pay component, the peak-window boundaries, rounding, the daily bonus threshold, malformed lines, duplicate IDs, midnight crossings, timestamp formats, and input mutation.
  • scenarios.py. A sample day of seven lines, including one malformed line and one duplicate. Prints PASS when the total is 2860 cents.
  • README.md. Run commands and ground rules.

Out of the box, all 19 tests error because calculate_payout raises NotImplementedError.

Your task

Implement calculate_payout(lines) so it returns the day's payout as an integer number of cents. Each line has the form <delivery_id>,<accept_time>,<fulfil_time>, with ISO 8601 local times. The formula is defined for this lesson, not taken from DoorDash:

  • Each valid delivery pays 200 cents plus 15 cents per active minute, where a partial minute rounds up.
  • A delivery accepted from 11:00 up to 14:00, or from 17:00 up to 21:00, earns a 100-cent peak bonus. The accept time decides, not the fulfil time.
  • A day with 8 or more valid deliveries earns a one-time 1000-cent bonus.

Skip malformed lines: the wrong number of fields, a blank ID, a timestamp that doesn't parse or has a numeric offset, or a fulfil time that isn't after the accept time. A trailing Z and surrounding whitespace are fine. For a repeated ID, the first valid line counts, and a malformed line doesn't reserve its ID. Keep all money in integers and don't mutate the input. The docstring in payout.py has the complete rules.

["D1,2026-11-16T08:05:00,2026-11-16T08:27:00"] -> 530 (22 min, off-peak) ["D1,2026-11-16T12:00:00,2026-11-16T12:20:00"] -> 600 (20 min, peak) ["D1,2026-11-16T08:05:00,2026-11-16T08:05:30"] -> 215 (30 s rounds up to 1 min) ["D1,2026-11-16T23:50:00,2026-11-17T00:10:00"] -> 500 (crosses midnight) eight 10-minute off-peak deliveries -> 3800 (2800 + 1000 bonus) ["garbage", "D1,bad,bad"] -> 0 [] -> 0

You're done when all 19 tests pass and python3 scenarios.py prints PASS.

The overlapping deliveries follow-up

A Dasher can accept a second delivery before fulfilling the first. If two deliveries both run from 12:00 to 12:20, your function pays 40 active minutes for 20 minutes of clock time. The interviewer asks whether that's right, and how you'd pay for busy time instead. Talk through who decides, what you'd need to compute it, and which deliveries would pay less.

Using AI on this problem

Screens like this usually allow AI for lookups, such as how datetime.fromisoformat treats a trailing Z in Python 3.11. Write the malformed-line policy and the duplicate rule yourself, because stating those rules is most of the signal. If AI drafts the payout loop, check it by hand against the 30-second delivery, the 10:50 accept with an 11:05 fulfil, and a malformed line followed by a valid one with the same ID.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.