Problem: Dasher pay calculation + peak-hour earnings
You are given historical delivery records for a driver (“dasher”). Each record contains:
-
start_time
and
end_time
(timestamps)
-
base_pay
(non-negative integer cents)
-
tip
(non-negative integer cents)
-
(optional)
bonus
(non-negative integer cents, may be missing)
Assume total pay for a record is:
\text{record_pay} = \text{base_pay} + \text{tip} + \text{bonus (if present, else 0)}
Part 1
Compute the dasher’s total pay across all records.
Part 2
Given a peak hour window [peak_start, peak_end) (timestamps), compute the dasher’s total pay attributable to deliveries that overlap that window.
-
A delivery “overlaps” the peak window if its time interval intersects
[peak_start, peak_end)
.
-
If a delivery only partially overlaps the window, assume you should
pro-rate pay by overlap duration
(unless you explicitly choose a different reasonable assumption—state it clearly).
Follow-up (data quality)
If the input data can be wrong or inconsistent (e.g., missing fields, negative values, end_time < start_time, duplicate records, overlapping records, bad timestamps), how should your solution handle it? Describe the approach (validation, skipping, correcting, logging, etc.).
Input/Output expectations
-
Input: an array/list of delivery records and (for Part 2) a peak time window.
-
Output: numeric totals (e.g., in cents).
-
Constraints: up to millions of records; aim for an efficient single-pass solution when possible.