Katkat

Compute dasher pay with peak-hour query

DoorDashSoftware Engineer · Onsite

Last updated

This question tests the ability to handle overlapping time intervals and perform weighted calculations based on time-based pay multipliers.

Problem Statement

You are tasked with building a pay calculator for delivery drivers. A driver's base pay is $10 per hour. During specific 'peak' intervals, the driver receives a multiplier applied to their base pay. Your goal is to compute the total earnings for a single delivery task given a start time, an end time, and a list of peak-hour intervals.

Function Signature

def calculate_driver_pay(start_time, end_time, peak_intervals):
    # start_time, end_time: integers representing minutes from start of day
    # peak_intervals: list of tuples (peak_start, peak_end, multiplier)
    # Returns: float (total pay)

Constraints

  • 0 <= start_time < end_time <= 1440
  • peak_intervals may overlap and are not necessarily sorted.
  • If multiple multipliers apply to the same minute, the highest multiplier is used.
  • Base pay is applied per-minute (base rate = $10/60 per minute).

Example 1

Input: start_time = 60 (1:00 AM) end_time = 120 (2:00 AM) peak_intervals = [(30, 90, 1.5)]

Calculation:

  • Minutes 60 to 90 (30 mins): Pay = $30 * (10/60) * 1.5 = $7.5
  • Minutes 90 to 120 (30 mins): Pay = $30 * (10/60) * 1.0 = $5.0
  • Output: $12.5

Edge Cases

  • Delivery period does not overlap with any peak intervals.
  • Delivery period completely contained within a single peak interval.
  • Multipliers are less than 1.0 (invalid input, treat as 1.0) or overlap creating complex zones.

Hints

Hint 1

Represent the time range as a discrete timeline or a set of interval segments.

Hint 2

For each minute in the delivery window, calculate the maximum applicable multiplier.

Hint 3

Consider using a sweep-line algorithm or mapping all peak intervals to an array of size 1440 if performance allows.

Follow-up questions

  • How would you optimize this if you had to process millions of deliveries against thousands of peak-hour rules?
  • How would you modify your solution if the pay multiplier was additive (e.g., base + $2.00) instead of multiplicative?
  • What data structures would you use to store peak intervals to perform efficient lookups during the calculation?