PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • DoorDash
  • Coding & Algorithms
  • Software Engineer

Compute dasher pay with peak-hour query

Company: DoorDash

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## 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.

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

You are given historical delivery records for a dasher. Each record is a list `[start_time, end_time, base_pay, tip, bonus]` where: - `start_time`, `end_time` are integer timestamps - `base_pay`, `tip`, `bonus` are non-negative integer cents (an absent bonus is represented as `0`) The pay for a single record is `base_pay + tip + bonus`. Return the dasher's **total pay** (in cents) summed across all records. **Example** ``` records = [[0, 10, 500, 200, 100], [20, 30, 600, 0, 0]] -> (500+200+100) + (600+0+0) = 1400 ``` Aim for a single O(n) pass over the records.

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

  1. The answer is just a running sum; no sorting or extra structures are needed.
  2. Each record contributes base_pay + tip + bonus, and bonus is already 0 when missing.
  3. Watch for an empty input list — the total should be 0.

Dasher Peak-Hour Pay (Pro-Rated)

You are given the same delivery records `[start_time, end_time, base_pay, tip, bonus]` plus a peak-hour window `[peak_start, peak_end)` (half-open, integer timestamps). A delivery **overlaps** the window if its interval `[start_time, end_time)` intersects `[peak_start, peak_end)`. For an overlapping delivery, pro-rate its pay by the fraction of the delivery's duration that falls inside the window: ``` record_pay = base_pay + tip + bonus overlap = max(0, min(end_time, peak_end) - max(start_time, peak_start)) duration = end_time - start_time contribution = record_pay * overlap / duration (integer floor) ``` Return the **total pro-rated pay** (in cents) attributable to the peak window. Use integer floor division so the result is a deterministic integer. **Data-quality note:** skip any record with `end_time <= start_time` (zero or negative duration) — it cannot be pro-rated. **Example** ``` records = [[0, 10, 800, 0, 0]], peak = [5, 10) overlap = 5, duration = 10 -> 800 * 5 // 10 = 400 ```

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

  1. Overlap of two intervals is max(0, min(end, peak_end) - max(start, peak_start)).
  2. A delivery fully inside the window contributes its entire pay; a delivery fully outside contributes 0.
  3. Pro-rate with record_pay * overlap // duration. Floor division keeps the answer an integer and consistent across languages.
  4. Guard against duration <= 0 (end_time <= start_time) before dividing — those records are invalid and should be skipped.
Last updated: Jun 21, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Validate a Shopping Cart - DoorDash (medium)
  • Calculate Driver Payments - DoorDash (medium)
  • Implement Timeout Refund Workflow - DoorDash (medium)
  • Maximize Chef Assignment Profit - DoorDash (medium)
  • Compute Courier Delivery Pay - DoorDash (easy)