Calculate Driver Payments
Company: DoorDash
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates a candidate's ability to implement interval arithmetic and overlap computation, perform data deduplication and filtering, handle per-delivery monetary rounding, and reason about idempotency and payment-workflow edge cases.
Constraints
- 0 <= len(deliveries) <= 5000
- 0 <= len(surge_windows) <= 1000
- delivery_id and driver_id are integers
- 0 <= start_time < end_time <= 10^9 for every delivery and surge window
- 0 <= rate_cents_per_minute <= 100000
- 1.0 <= multiplier <= 10.0
- Surge windows do not overlap, but they may be unsorted and may touch at endpoints
Examples
Input: ([[101, 1, 0, 30, 100], [102, 1, 50, 60, 200]], [], [[10, 20, 2.0]], 1)
Expected Output: (6000, [101, 102])
Explanation: Delivery 101 has 30 base minutes = 3000 cents plus 10 surged minutes adding another 1000 cents. Delivery 102 has no surge and pays 2000 cents.
Input: ([[201, 7, 0, 10, 100], [202, 7, 0, 10, 100], [201, 7, 0, 10, 500], [203, 8, 0, 10, 1000], [204, 7, 5, 15, 100]], [202], [[8, 12, 2.0]], 7)
Expected Output: (2600, [201, 204])
Explanation: Delivery 202 is already paid, delivery 201's duplicate is ignored, and delivery 203 belongs to another driver. Delivery 201 pays 1200 cents and delivery 204 pays 1400 cents.
Input: ([[301, 5, 0, 1, 101]], [], [[0, 1, 1.5]], 5)
Expected Output: (152, [301])
Explanation: The delivery earns 101 * 1.5 = 151.5 cents, rounded half-up at the end of the delivery to 152 cents.
Input: ([], [], [[0, 10, 2.0]], 1)
Expected Output: (0, [])
Explanation: There are no deliveries to pay.
Input: ([[401, 2, 10, 20, 100]], [], [[0, 10, 3.0], [20, 30, 3.0]], 2)
Expected Output: (1000, [401])
Explanation: Surge windows that only touch the delivery boundary do not overlap the half-open delivery interval [10, 20), so only base pay applies.
Hints
- Use sets to track delivery ids that were already paid and delivery ids you have already counted during this calculation.
- For a delivery and a surge window, the overlap length is max(0, min(delivery_end, surge_end) - max(delivery_start, surge_start)).