DoorDash CodingFree previewFree
Dasher Pay With Peak Hours
Last asked
Problem
Compute a dasher's total pay for one day of order events, where every active order earns a base rate per minute so concurrent orders stack, then add peak-time windows that pay double.
An order becomes active at its start event and stops at its end event. At any instant the pay rate is base_rate * active_orders. Times are integer minutes and intervals are half-open, [start, end).
The prompt is deliberately vague: settle the rules with the interviewer before coding, including how concurrent orders are paid, whether canceled orders still pay, whether events can arrive out of order, and the input shape.
Part 1 — Base pay
Sum, over every time segment, the segment length times the number of active orders times the base rate.
Part 2 — Peak hours
Add peak-time windows (for example 5 to 7 pm) during which the rate doubles to 2 * base_rate * active_orders. A window boundary that falls between two order events splits that segment. Overlapping windows still pay only 2x.
Variant — More statuses
Events also carry the statuses failed, canceled and return, each recorded with who caused it: the user, the merchant or the dasher (for example canceled by dasher). Decide with the interviewer how each status affects pay, including inside peak windows.
Starter code
import sys
def main() -> None:
# read N R, the N events, M and the M peak windows from stdin; print the total pay
...
if __name__ == "__main__":
main()Input
First line N R: the number of order events and the base pay per active order per minute. Then N lines T ORDER_ID ACTION, where ACTION is START or END. Then a line M, the number of peak windows, followed by M lines P_START P_END, each a half-open peak window.
Output
Print the total pay as an integer.
Constraints
1 <= N <= 2 * 10^5
0 <= M <= 2 * 10^5
0 <= T, P_START, P_END <= 10^9
Every order has exactly one START and one later END event
Events are not necessarily sorted
Examples
Example 1
Input
4 1 0 A START 10 A END 5 B START 15 B END 1 7 12
Output
28
Explanation
Base pay is 10 for A and 10 for B. The peak window [7, 12) overlaps A for 3 minutes and B for 5, adding 8.
Follow-ups
Handle Part 2 without sorting the input: merge the pre-sorted peak times into the events, for example by binary search, or use a sweep line.
Use prefix sums over the peak windows so each order's pay is O(1) after preprocessing.
How do you handle duplicate upstream events (idempotency)?
What do you do when the payment service or an upstream API is unavailable?
How would you turn the batch script into a live service?
Which edge cases should you consider?
Loading the solution…
