Compute Driver Pay with Double-Pay Windows
DoorDashSoftware Engineer · Technical ScreenLast updated
This question evaluates a candidate's ability to perform interval arithmetic and aggregation for time-based pay computations, including handling overlapping intervals, half-open boundaries, capped double-pay application, and special-case handling for canceled orders.
You are building payroll logic for a delivery platform.
Given a list of order records for one delivery driver, compute the total amount the driver should be paid.
Each order record contains:
order_id: a unique identifierstatus: either"delivered"or"canceled"start_time: delivery start time, represented as an integer timestamp in minutesend_time: delivery end time, represented as an integer timestamp in minuteshourly_rate: the driver's normal hourly rate for that order
Additional inputs:
canceled_order_compensation: a fixed payment amount for each canceled orderdouble_pay_windows: a list of time intervals[start_time, end_time)during which delivered work should be paid at double the normal hourly rate
Payment rules:
- For a delivered order, pay the driver based on the delivery duration and hourly rate.
- Any portion of a delivered order that overlaps a double-pay window should be paid at double rate.
- Portions that do not overlap any double-pay window should be paid at normal rate.
- If multiple double-pay windows overlap, the driver should still receive at most double pay for any minute, not triple or more.
- For a canceled order, pay only the fixed
canceled_order_compensation; do not apply hourly or double-pay calculations. - Treat all intervals as half-open:
[start_time, end_time).
Return the driver's total pay as a numeric value.
Example:
orders = [
{ order_id: "A", status: "delivered", start_time: 60, end_time: 120, hourly_rate: 30 },
{ order_id: "B", status: "canceled", start_time: 130, end_time: 160, hourly_rate: 30 },
{ order_id: "C", status: "delivered", start_time: 150, end_time: 210, hourly_rate: 24 }
]
canceled_order_compensation = 5
double_pay_windows = [
[90, 150],
[180, 240]
]
Order A lasts 60 minutes. Minutes [60, 90) are paid normally, and [90, 120) are paid at double rate.
Order B is canceled, so it pays 5.
Order C lasts 60 minutes. Minutes [150, 180) are paid normally, and [180, 210) are paid at double rate.
Compute and return the total pay.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.