PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's ability to work with time-interval arithmetic, interval union/overlap reasoning, and aggregation of time-based pay, testing skills in algorithms and data handling for billing computations.

  • easy
  • DoorDash
  • Coding & Algorithms
  • Software Engineer

Compute Courier Delivery Pay

Company: DoorDash

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

A delivery platform has a service that can return all orders delivered by a courier. You are given: - `courierId`: the courier's identifier. - `ratePerMinute`: the courier's pay rate. - A service method such as `getOrders(courierId)` that returns a list of orders. Each order has: - `startTime`: when the courier started working on that order. - `endTime`: when the courier completed that order. Assume times are represented as integer minutes and `endTime >= startTime`. Implement a function to compute how much the courier should be paid. Base requirement: - Each order is paid independently. - Total pay is the sum of `(endTime - startTime) * ratePerMinute` across all orders. Follow-up: - Couriers may handle multiple orders at the same time, so order intervals can overlap. - Implement a second version that computes pay based on actual active working time, where overlapping intervals are counted only once. - For example, if the courier has orders `[10, 20]` and `[15, 25]`, the active working time is `15` minutes, not `20` minutes.

Quick Answer: This question evaluates a candidate's ability to work with time-interval arithmetic, interval union/overlap reasoning, and aggregation of time-based pay, testing skills in algorithms and data handling for billing computations.

Part 1: Compute Courier Pay by Summing Each Order

You are given the pay rate for one courier and a list of that courier's delivered orders. Each order is represented by a pair `(startTime, endTime)` in integer minutes, with `endTime >= startTime`. Each order is paid independently, even if some orders overlap in time. Compute the courier's total pay. The total pay is: `sum((endTime - startTime) * ratePerMinute for each order)`

Constraints

  • 0 <= len(orders) <= 200000
  • 0 <= startTime <= endTime <= 10^9
  • 0 <= ratePerMinute <= 10^6
  • The final answer fits in a 64-bit signed integer

Examples

Input: (2, [(10, 20), (20, 35)])

Expected Output: 50

Explanation: Durations are 10 and 15 minutes. Total minutes = 25, so pay = 25 * 2 = 50.

Input: (3, [(10, 20), (15, 25)])

Expected Output: 60

Explanation: Orders overlap, but in this part they are paid independently. Total minutes = 10 + 10 = 20, so pay = 20 * 3 = 60.

Input: (5, [])

Expected Output: 0

Explanation: No orders means no pay.

Input: (4, [(7, 7), (7, 10)])

Expected Output: 12

Explanation: The first order lasts 0 minutes and the second lasts 3 minutes. Total pay = 3 * 4 = 12.

Hints

  1. You do not need to compare one order with another in this part.
  2. For each order, compute its duration first, then multiply by the rate.

Part 2: Compute Courier Pay from Actual Active Working Time

You are given the pay rate for one courier and a list of that courier's delivered orders. Each order is represented by a pair `(startTime, endTime)` in integer minutes, with `endTime >= startTime`. Unlike Part 1, the courier may work on multiple orders at the same time. Overlapping time must be counted only once. Compute pay based on the courier's actual active working time. In other words, find the total length of the union of all order intervals, then multiply by `ratePerMinute`. Example: orders `(10, 20)` and `(15, 25)` have active working time `15` minutes, so with rate `r` the pay is `15 * r`. Treat intervals as continuous working periods, so orders that touch at endpoints, such as `(10, 20)` and `(20, 25)`, contribute `15` total minutes.

Constraints

  • 0 <= len(orders) <= 200000
  • 0 <= startTime <= endTime <= 10^9
  • 0 <= ratePerMinute <= 10^6
  • The final answer fits in a 64-bit signed integer

Examples

Input: (2, [(10, 20), (15, 25)])

Expected Output: 30

Explanation: The merged active interval is (10, 25), which lasts 15 minutes. Pay = 15 * 2 = 30.

Input: (3, [(1, 5), (5, 8), (10, 12)])

Expected Output: 27

Explanation: The first two orders touch, so they form 7 active minutes from 1 to 8. The third adds 2 more minutes. Total = 9, so pay = 9 * 3 = 27.

Input: (1, [(30, 40), (10, 20), (15, 18), (20, 30)])

Expected Output: 30

Explanation: After sorting and merging, all orders combine into one active interval from 10 to 40, which is 30 minutes.

Input: (7, [])

Expected Output: 0

Explanation: No orders means no active time and no pay.

Input: (4, [(5, 5), (5, 10), (8, 8)])

Expected Output: 20

Explanation: Zero-length orders add no time. The only active span is from 5 to 10, which is 5 minutes. Pay = 5 * 4 = 20.

Hints

  1. Sort the intervals by start time before processing them.
  2. Keep track of the current merged interval; when the next order starts after it ends, add the finished interval's length to the answer.
Last updated: May 7, 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 Nearest Destination Distances - DoorDash (easy)