Design a Delivery Driver Salary System
You are designing an in-memory payroll service that calculates and pays delivery drivers based on their worked time. The system must provide accurate cost accruals, support partial payments up to a boundary time, and avoid double-paying overlapping work intervals.
Assumptions (make minimal changes if needed):
-
Time values are Unix timestamps in seconds; intervals use half-open semantics [start_time, end_time).
-
Each driver has a constant USD hourly rate after Add_driver (rate changes are out of scope but can be added as an extension).
-
Record_delivery only records completed deliveries (end_time > start_time). Deliveries can be inserted out of chronological order.
-
For a given driver, overlapping or adjacent delivery intervals should be merged so the driver is not double-paid for the same minute twice.
-
Monetary values are tracked in integer cents to avoid floating-point error.
APIs to support:
-
Add_driver(driver_id, usd_hourly_rate)
-
Record_delivery(driver_id, start_time, end_time)
-
Get_Total_Cost()
-
Pay_Up_To(pay_time)
-
Total_Cost_Unpaid()
Explain:
-
Data structures to store drivers, delivery intervals, rates, and payments.
-
State-mutation logic for each API, including handling overlaps and partial payments.
-
Object-oriented design that enables accurate and efficient payroll computation, plus complexity trade-offs.