PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's ability to implement interval arithmetic and overlap computation, perform data deduplication and filtering, handle per-delivery monetary rounding, and reason about idempotency and payment-workflow edge cases.

  • medium
  • DoorDash
  • Coding & Algorithms
  • Software Engineer

Calculate Driver Payments

Company: DoorDash

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Build a payout calculator for a delivery platform. You are given: - A list of delivery records. Each record has `delivery_id`, `driver_id`, `start_time`, `end_time`, and `rate_cents_per_minute`. - A set of `already_paid_delivery_ids`. - A list of surge windows, each with `start_time`, `end_time`, and `multiplier`; for example, rush hour may have multiplier `2.0`. For one driver, compute the total payout in cents and the list of delivery ids that should be marked as paid. Rules: 1. Ignore deliveries for other drivers. 2. A delivery with an id already in `already_paid_delivery_ids` must not be paid again. 3. If duplicate records with the same `delivery_id` appear in the input, count that delivery once. 4. Pay is calculated per delivery for the interval `[start_time, end_time)`. If a surge window overlaps only part of a delivery, apply the multiplier only to the overlapping minutes. 5. Assume times are integer minutes and money is rounded to integer cents at the end of each delivery. Follow-ups: - How would you make the payout operation idempotent if the payment API can time out and the job may be retried? - How would you handle multiple overlapping surge windows? - How would the algorithm change if the business wants to pay only for the union of active time rather than independently per delivery?

Quick Answer: This question evaluates a candidate's ability to implement interval arithmetic and overlap computation, perform data deduplication and filtering, handle per-delivery monetary rounding, and reason about idempotency and payment-workflow edge cases.

Build a payout calculator for a delivery platform. Implement a function that computes the payout for one driver, excluding deliveries that have already been paid or are duplicates. Each delivery is paid for the half-open interval [start_time, end_time). Base pay is rate_cents_per_minute for every active minute. If a non-overlapping surge window overlaps part of a delivery, apply that surge multiplier only to the overlapping minutes. Minutes outside surge windows use multiplier 1.0. If the same delivery_id appears more than once for the target driver, count only its first unpaid occurrence. Round money to integer cents at the end of each delivery using nearest-integer rounding with halves rounded up. Return the total payout in cents and the delivery ids that should now be marked as paid, in the order they are first paid from the input.

Constraints

  • 0 <= len(deliveries) <= 5000
  • 0 <= len(surge_windows) <= 1000
  • delivery_id and driver_id are integers
  • 0 <= start_time < end_time <= 10^9 for every delivery and surge window
  • 0 <= rate_cents_per_minute <= 100000
  • 1.0 <= multiplier <= 10.0
  • Surge windows do not overlap, but they may be unsorted and may touch at endpoints

Examples

Input: ([[101, 1, 0, 30, 100], [102, 1, 50, 60, 200]], [], [[10, 20, 2.0]], 1)

Expected Output: (6000, [101, 102])

Explanation: Delivery 101 has 30 base minutes = 3000 cents plus 10 surged minutes adding another 1000 cents. Delivery 102 has no surge and pays 2000 cents.

Input: ([[201, 7, 0, 10, 100], [202, 7, 0, 10, 100], [201, 7, 0, 10, 500], [203, 8, 0, 10, 1000], [204, 7, 5, 15, 100]], [202], [[8, 12, 2.0]], 7)

Expected Output: (2600, [201, 204])

Explanation: Delivery 202 is already paid, delivery 201's duplicate is ignored, and delivery 203 belongs to another driver. Delivery 201 pays 1200 cents and delivery 204 pays 1400 cents.

Input: ([[301, 5, 0, 1, 101]], [], [[0, 1, 1.5]], 5)

Expected Output: (152, [301])

Explanation: The delivery earns 101 * 1.5 = 151.5 cents, rounded half-up at the end of the delivery to 152 cents.

Input: ([], [], [[0, 10, 2.0]], 1)

Expected Output: (0, [])

Explanation: There are no deliveries to pay.

Input: ([[401, 2, 10, 20, 100]], [], [[0, 10, 3.0], [20, 30, 3.0]], 2)

Expected Output: (1000, [401])

Explanation: Surge windows that only touch the delivery boundary do not overlap the half-open delivery interval [10, 20), so only base pay applies.

Hints

  1. Use sets to track delivery ids that were already paid and delivery ids you have already counted during this calculation.
  2. For a delivery and a surge window, the overlap length is max(0, min(delivery_end, surge_end) - max(delivery_start, surge_start)).
Last updated: Jun 13, 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)
  • Implement Timeout Refund Workflow - DoorDash (medium)
  • Maximize Chef Assignment Profit - DoorDash (medium)
  • Compute Courier Delivery Pay - DoorDash (easy)
  • Compute Nearest Destination Distances - DoorDash (easy)