Compute total courier pay with peak-hour multipliers

Quick Overview

Compute a courier's total pay from paired ACCEPT and FULFILL events when parts of each delivery fall inside peak-hour windows that carry pay multipliers. It tests interval overlap arithmetic, choosing the highest multiplier where peak windows overlap, and per-minute rate bookkeeping.

Compute total courier pay with peak-hour multipliers

Company: DoorDash

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

Given a sequence of delivery events and a list of peak hour intervals with multipliers, calculate the total pay for a courier. Each event is either an `ACCEPT` event (with a timestamp and base pay) or a `FULFILL` event (with a timestamp). Events come in pairs: each `ACCEPT` is followed by its corresponding `FULFILL`. A delivery's active time spans from its `ACCEPT` timestamp to its `FULFILL` timestamp. Each peak hour interval is defined as `[start, end, multiplier]`. If any portion of a delivery's active time overlaps with a peak interval, that overlapping portion earns pay at the peak multiplier rate. Non-overlapping portions earn at the base rate (1x). The base pay per minute is `base_pay / total_delivery_minutes`, where `total_delivery_minutes` is the `FULFILL` timestamp minus the `ACCEPT` timestamp, so a delivery with no peak overlap earns exactly its base pay. If multiple peak intervals overlap, use the highest multiplier for the overlapping segment. Return the total pay rounded to 2 decimal places. ### Function Signature ```python def compute_courier_pay(events: list[list], peak_hours: list[list[float]]) -> float: ``` ### Rules - An `ACCEPT` event is `["ACCEPT", timestamp, base_pay]` and a `FULFILL` event is `["FULFILL", timestamp]`. Timestamps are in minutes. - Events alternate: `events[0]` is an `ACCEPT`, `events[1]` is its `FULFILL`, `events[2]` is the next `ACCEPT`, and so on. - Overlap is the length of the intersection of the delivery's active time and the peak interval. A peak interval that only touches a delivery at an endpoint adds nothing. - At any moment of a delivery, the multiplier is the largest multiplier among the peak intervals covering that moment, or 1 when none covers it. - Each delivery is paid on its own. If the active times of two deliveries overlap, each still earns its full pay for the shared minutes. - Return the sum over all deliveries as a float rounded to 2 decimal places. ### Constraints - `2 <= len(events) <= 1000`, and `len(events)` is even - For each delivery, the `ACCEPT` timestamp is less than the `FULFILL` timestamp - `0 <= len(peak_hours) <= 100` - Each peak interval `[start, end, multiplier]` has `start < end` and `multiplier >= 1.0` - Each `base_pay` is a positive number ### Examples #### Example 1 ```text Input: events = [["ACCEPT", 0, 20], ["FULFILL", 10], ["ACCEPT", 15, 30], ["FULFILL", 25]], peak_hours = [[5, 8, 2]] Output: 56.0 ``` The first delivery runs from minute 0 to 10 at 2 per minute. Minutes 5 to 8 fall in the 2x window, so it earns `7 * 2 + 3 * 2 * 2 = 26`. The second delivery (minutes 15 to 25, 3 per minute) misses the window and earns its base 30, for a total of 56. #### Example 2 ```text Input: events = [["ACCEPT", 0, 10], ["FULFILL", 10]], peak_hours = [[0, 10, 3]] Output: 30.0 ``` The delivery lies entirely inside the 3x window. Its base rate is 1 per minute, so it earns `10 * 1 * 3 = 30`. #### Example 3 ```text Input: events = [["ACCEPT", 0, 60], ["FULFILL", 60]], peak_hours = [[10, 30, 1.5], [20, 40, 2]] Output: 85.0 ``` The base rate is 1 per minute. Minutes 0-10 earn 10, minutes 10-20 earn 15 at 1.5x, minutes 20-40 earn 40 at 2x (the two windows overlap on 20-30, and the higher multiplier wins there), and minutes 40-60 earn 20. The total is 85.

Overview: Compute a courier's total pay from paired ACCEPT and FULFILL events when parts of each delivery fall inside peak-hour windows that carry pay multipliers. It tests interval overlap arithmetic, choosing the highest multiplier where peak windows overlap, and per-minute rate bookkeeping.

DoorDash logo
DoorDash
Nov 24, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Given a sequence of delivery events and a list of peak hour intervals with multipliers, calculate the total pay for a courier.

Each event is either an ACCEPT event (with a timestamp and base pay) or a FULFILL event (with a timestamp). Events come in pairs: each ACCEPT is followed by its corresponding FULFILL. A delivery's active time spans from its ACCEPT timestamp to its FULFILL timestamp.

Each peak hour interval is defined as [start, end, multiplier]. If any portion of a delivery's active time overlaps with a peak interval, that overlapping portion earns pay at the peak multiplier rate. Non-overlapping portions earn at the base rate (1x). The base pay per minute is base_pay / total_delivery_minutes, where total_delivery_minutes is the FULFILL timestamp minus the ACCEPT timestamp, so a delivery with no peak overlap earns exactly its base pay. If multiple peak intervals overlap, use the highest multiplier for the overlapping segment.

Return the total pay rounded to 2 decimal places.

Function Signature

def compute_courier_pay(events: list[list], peak_hours: list[list[float]]) -> float:

Rules

  • An ACCEPT event is ["ACCEPT", timestamp, base_pay] and a FULFILL event is ["FULFILL", timestamp] . Timestamps are in minutes.
  • Events alternate: events[0] is an ACCEPT , events[1] is its FULFILL , events[2] is the next ACCEPT , and so on.
  • Overlap is the length of the intersection of the delivery's active time and the peak interval. A peak interval that only touches a delivery at an endpoint adds nothing.
  • At any moment of a delivery, the multiplier is the largest multiplier among the peak intervals covering that moment, or 1 when none covers it.
  • Each delivery is paid on its own. If the active times of two deliveries overlap, each still earns its full pay for the shared minutes.
  • Return the sum over all deliveries as a float rounded to 2 decimal places.

Constraints

  • 2 <= len(events) <= 1000 , and len(events) is even
  • For each delivery, the ACCEPT timestamp is less than the FULFILL timestamp
  • 0 <= len(peak_hours) <= 100
  • Each peak interval [start, end, multiplier] has start < end and multiplier >= 1.0
  • Each base_pay is a positive number

Examples

Example 1

Input: events = [["ACCEPT", 0, 20], ["FULFILL", 10], ["ACCEPT", 15, 30], ["FULFILL", 25]], peak_hours = [[5, 8, 2]]
Output: 56.0

The first delivery runs from minute 0 to 10 at 2 per minute. Minutes 5 to 8 fall in the 2x window, so it earns 7 * 2 + 3 * 2 * 2 = 26. The second delivery (minutes 15 to 25, 3 per minute) misses the window and earns its base 30, for a total of 56.

Example 2

Input: events = [["ACCEPT", 0, 10], ["FULFILL", 10]], peak_hours = [[0, 10, 3]]
Output: 30.0

The delivery lies entirely inside the 3x window. Its base rate is 1 per minute, so it earns 10 * 1 * 3 = 30.

Example 3

Input: events = [["ACCEPT", 0, 60], ["FULFILL", 60]], peak_hours = [[10, 30, 1.5], [20, 40, 2]]
Output: 85.0

The base rate is 1 per minute. Minutes 0-10 earn 10, minutes 10-20 earn 15 at 1.5x, minutes 20-40 earn 40 at 2x (the two windows overlap on 20-30, and the higher multiplier wins there), and minutes 40-60 earn 20. The total is 85.