Katkat

Compute Driver Pay with Double-Pay Windows

DoorDashSoftware Engineer · Technical Screen

Last 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 identifier
  • status: either "delivered" or "canceled"
  • start_time: delivery start time, represented as an integer timestamp in minutes
  • end_time: delivery end time, represented as an integer timestamp in minutes
  • hourly_rate: the driver's normal hourly rate for that order

Additional inputs:

  • canceled_order_compensation: a fixed payment amount for each canceled order
  • double_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:

  1. For a delivered order, pay the driver based on the delivery duration and hourly rate.
  2. Any portion of a delivered order that overlaps a double-pay window should be paid at double rate.
  3. Portions that do not overlap any double-pay window should be paid at normal rate.
  4. If multiple double-pay windows overlap, the driver should still receive at most double pay for any minute, not triple or more.
  5. For a canceled order, pay only the fixed canceled_order_compensation; do not apply hourly or double-pay calculations.
  6. 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.