Compute Driver Pay with Double-Pay Windows
Company: DoorDash
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: 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.
Constraints
- 0 <= len(orders), len(double_pay_windows) <= 10^5
- For every order, `start_time <= end_time`
- For every double-pay window, `start_time <= end_time`
- Timestamps are integers in minutes
- Statuses are valid and are either `delivered` or `canceled`
Examples
Input: ([{'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}], 5, [[90, 150], [180, 240]])
Expected Output: 86.0
Explanation: Order A pays 45.0, order B pays 5.0, and order C pays 36.0, for a total of 86.0.
Input: ([{'order_id': 'X', 'status': 'delivered', 'start_time': 0, 'end_time': 60, 'hourly_rate': 60}, {'order_id': 'Y', 'status': 'delivered', 'start_time': 60, 'end_time': 120, 'hourly_rate': 60}], 7, [[80, 100], [20, 50], [40, 80]])
Expected Output: 200.0
Explanation: The windows merge into one covered interval [20, 100). Each 60-minute order has 40 double-paid minutes and 20 normal minutes, so each pays 100.0.
Input: ([{'order_id': 'C1', 'status': 'canceled', 'start_time': 10, 'end_time': 40, 'hourly_rate': 30}, {'order_id': 'C2', 'status': 'canceled', 'start_time': 50, 'end_time': 90, 'hourly_rate': 45}], 8, [])
Expected Output: 16.0
Explanation: Both orders are canceled, so each pays only the fixed compensation of 8.
Input: ([], 5, [[0, 100]])
Expected Output: 0.0
Explanation: There are no orders, so the total pay is 0.
Input: ([{'order_id': 'D', 'status': 'delivered', 'start_time': 30, 'end_time': 30, 'hourly_rate': 120}, {'order_id': 'E', 'status': 'canceled', 'start_time': 10, 'end_time': 20, 'hourly_rate': 50}], 3, [[0, 60]])
Expected Output: 3.0
Explanation: The delivered order has zero duration, so it pays 0. The canceled order pays the fixed compensation of 3.
Input: ([{'order_id': 'M', 'status': 'delivered', 'start_time': 0, 'end_time': 180, 'hourly_rate': 60}], 4, [[120, 150], [30, 60], [90, 120]])
Expected Output: 270.0
Explanation: The covered minutes are [30, 60) and [90, 150), for 90 double-paid minutes total. The order lasts 180 minutes, so pay is (180 normal-base minutes + 90 extra double-pay minutes) * 60 / 60 = 270.0.
Hints
- First merge the double-pay windows so that overlapping windows do not cause the same minute to be counted more than once.
- After merging, use binary search plus prefix sums of covered minutes to compute how many minutes of each delivered order fall inside the union of double-pay windows.