Compute dasher pay with peak-hour query
Company: DoorDash
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates a candidate's ability to perform time-interval arithmetic, prorated pay aggregation, robust handling of missing or inconsistent fields, and efficient large-scale data processing.
Dasher Total Pay
Constraints
- 0 <= number of records <= 10^6
- 0 <= base_pay, tip, bonus (each fits in a 32-bit int)
- An absent bonus is encoded as 0
- Aim for a single pass over the records
Examples
Input: ([[0, 10, 500, 200, 100], [20, 30, 600, 0, 0]],)
Expected Output: 1400
Explanation: First record pays 800, second pays 600; total 1400 cents.
Input: ([],)
Expected Output: 0
Explanation: No records means zero total pay.
Input: ([[5, 15, 1000, 350, 0]],)
Expected Output: 1350
Explanation: Single record: 1000 + 350 + 0 = 1350.
Input: ([[0, 5, 0, 0, 0]],)
Expected Output: 0
Explanation: A record with all zero pay components contributes 0.
Input: ([[0, 5, 250, 75, 25], [6, 9, 250, 75, 25], [10, 12, 250, 75, 25]],)
Expected Output: 1050
Explanation: Each record pays 350; three records total 1050.
Hints
- The answer is just a running sum; no sorting or extra structures are needed.
- Each record contributes base_pay + tip + bonus, and bonus is already 0 when missing.
- Watch for an empty input list — the total should be 0.
Dasher Peak-Hour Pay (Pro-Rated)
Constraints
- 0 <= number of records <= 10^6
- Timestamps are integers; the peak window [peak_start, peak_end) is half-open
- 0 <= base_pay, tip, bonus (each fits in a 32-bit int)
- Skip records with end_time <= start_time (zero/negative duration)
- Use integer floor division for the pro-rated contribution
Examples
Input: ([[0, 10, 500, 200, 100]], 0, 10)
Expected Output: 800
Explanation: Delivery fully inside the window: full pay 500+200+100 = 800.
Input: ([[0, 10, 800, 0, 0]], 5, 15)
Expected Output: 400
Explanation: Overlap is [5,10) = 5 of a 10-unit delivery: 800 * 5 // 10 = 400.
Input: ([[0, 10, 1000, 0, 0]], 20, 30)
Expected Output: 0
Explanation: No overlap with the peak window, so it contributes nothing.
Input: ([], 0, 100)
Expected Output: 0
Explanation: No records means zero peak pay.
Input: ([[0, 20, 1000, 0, 0], [10, 30, 600, 0, 0]], 5, 25)
Expected Output: 1200
Explanation: First: overlap 15/20 -> 1000*15//20 = 750. Second: overlap 15/20 -> 600*15//20 = 450. Total 1200.
Input: ([[5, 5, 1000, 0, 0]], 0, 10)
Expected Output: 0
Explanation: Zero-duration record (end == start) is skipped.
Input: ([[10, 5, 1000, 0, 0]], 0, 20)
Expected Output: 0
Explanation: Invalid record with end_time < start_time is skipped.
Input: ([[0, 3, 1000, 0, 0]], 1, 2)
Expected Output: 333
Explanation: Overlap 1 of duration 3: 1000 * 1 // 3 = 333 (floor).
Hints
- Overlap of two intervals is max(0, min(end, peak_end) - max(start, peak_start)).
- A delivery fully inside the window contributes its entire pay; a delivery fully outside contributes 0.
- Pro-rate with record_pay * overlap // duration. Floor division keeps the answer an integer and consistent across languages.
- Guard against duration <= 0 (end_time <= start_time) before dividing — those records are invalid and should be skipped.