PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates event-driven time-interval processing, interval-overlap arithmetic, rate computation, and robustness to malformed, duplicate, or unordered events when aggregating a driver's pay from a day's log.

  • hard
  • DoorDash
  • Coding & Algorithms
  • Software Engineer

Calculate Daily Driver Pay

Company: DoorDash

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are given a one-day event log for a delivery driver. Each input record is a JSON event with fields such as `order_id`, `event_type`, `timestamp`, and `base_rate_per_minute`. For each order, a valid pair of events defines a paid work interval: the order starts at its start event and ends at its completion event. The pay for that order is: `duration_in_minutes * base_rate_per_minute` Compute the driver's total pay for the day across all orders. Follow-up: some time ranges are marked as peak periods, during which the pay rate is doubled. If a paid interval partially overlaps a peak period, you must split the interval at every peak boundary and apply the doubled rate only to the overlapping sub-intervals. Assume timestamps are already normalized to comparable numeric values; timestamp parsing itself is not the focus. Also explain how you would handle malformed input such as missing events, duplicate events, or invalid event ordering.

Quick Answer: This question evaluates event-driven time-interval processing, interval-overlap arithmetic, rate computation, and robustness to malformed, duplicate, or unordered events when aggregating a driver's pay from a day's log.

Part 1: Total Driver Pay from Valid Order Intervals

You are given an unsorted list of event records for one delivery driver. Each record is a JSON-like Python dictionary with fields such as 'order_id', 'event_type', 'timestamp', and sometimes 'base_rate_per_minute'. A valid paid order interval is defined by exactly one 'start' event and exactly one 'complete' event for the same order, with complete_timestamp > start_timestamp. The pay for that order is (complete_timestamp - start_timestamp) * base_rate_per_minute, where the rate comes from the 'start' event. Ignore malformed orders entirely: orders with a missing start or completion event, duplicate start or completion events, a missing rate on the start event, or invalid ordering where completion time is not after start time. Ignore unrelated event types.

Constraints

  • 0 <= len(events) <= 200000
  • Timestamps and base rates are integers in the range [0, 10^9]
  • Events may appear in any order
  • Ignore malformed orders: missing start or complete, duplicate start/complete, missing start rate, or complete timestamp <= start timestamp

Examples

Input: [{'order_id': 'A', 'event_type': 'complete', 'timestamp': 25}, {'order_id': 'B', 'event_type': 'start', 'timestamp': 0, 'base_rate_per_minute': 3}, {'order_id': 'A', 'event_type': 'start', 'timestamp': 10, 'base_rate_per_minute': 2}, {'order_id': 'B', 'event_type': 'complete', 'timestamp': 5}]

Expected Output: 45

Explanation: Order A pays (25 - 10) * 2 = 30. Order B pays (5 - 0) * 3 = 15. Total = 45.

Input: [{'order_id': 'A', 'event_type': 'start', 'timestamp': 0, 'base_rate_per_minute': 2}, {'order_id': 'A', 'event_type': 'complete', 'timestamp': 10}, {'order_id': 'B', 'event_type': 'start', 'timestamp': 5, 'base_rate_per_minute': 4}, {'order_id': 'C', 'event_type': 'start', 'timestamp': 8, 'base_rate_per_minute': 5}, {'order_id': 'C', 'event_type': 'complete', 'timestamp': 3}, {'order_id': 'D', 'event_type': 'start', 'timestamp': 1, 'base_rate_per_minute': 7}, {'order_id': 'D', 'event_type': 'complete', 'timestamp': 6}, {'order_id': 'D', 'event_type': 'complete', 'timestamp': 9}]

Expected Output: 20

Explanation: Only A is valid. B is missing a completion, C completes before it starts, and D has duplicate completion events.

Input: []

Expected Output: 0

Explanation: No events means no valid paid intervals.

Input: [{'order_id': 'X', 'event_type': 'created', 'timestamp': 0}, {'order_id': 'X', 'event_type': 'start', 'timestamp': 10, 'base_rate_per_minute': 4}, {'order_id': 'X', 'event_type': 'picked_up', 'timestamp': 12}, {'order_id': 'X', 'event_type': 'complete', 'timestamp': 15}]

Expected Output: 20

Explanation: Unrelated event types are ignored. The valid interval is [10, 15), so pay is 5 * 4 = 20.

Hints

  1. Group events by order_id and track how many 'start' and 'complete' events each order has.
  2. Only add pay for orders that end up with exactly one valid start, exactly one valid completion, and start_timestamp < complete_timestamp.

Part 2: Total Driver Pay with Peak-Period Double Rates

You are given an unsorted list of event records for one delivery driver and a list of peak pay periods. Each event is a JSON-like Python dictionary with fields such as 'order_id', 'event_type', 'timestamp', and sometimes 'base_rate_per_minute'. A valid order interval is defined by exactly one 'start' event and exactly one 'complete' event for the same order, with complete_timestamp > start_timestamp. During peak periods, the driver's pay rate is doubled. If an order interval partially overlaps a peak period, only the overlapping portion gets double pay. Treat all intervals as half-open ranges [start, end). Peak periods may overlap each other; overlapping or adjacent peak periods should be merged into one continuous peak range. Ignore invalid peak periods where start >= end. Ignore malformed orders entirely: missing start or completion, duplicate start or completion, a missing rate on the start event, or invalid ordering.

Constraints

  • 0 <= len(events) <= 200000
  • 0 <= len(peak_periods) <= 200000
  • Timestamps and base rates are integers in the range [0, 10^9]
  • Ignore malformed orders as defined in Part 1
  • Ignore invalid peak periods where start >= end

Examples

Input: ([{'order_id': 'A', 'event_type': 'start', 'timestamp': 0, 'base_rate_per_minute': 3}, {'order_id': 'A', 'event_type': 'complete', 'timestamp': 10}], [(2, 5), (7, 9)])

Expected Output: 45

Explanation: Order A lasts 10 minutes at rate 3. Peak overlap is 3 minutes from [2,5) and 2 minutes from [7,9), total 5 peak minutes. Pay = 3 * (10 + 5) = 45.

Input: ([{'order_id': 'A', 'event_type': 'start', 'timestamp': 1, 'base_rate_per_minute': 2}, {'order_id': 'A', 'event_type': 'complete', 'timestamp': 8}, {'order_id': 'B', 'event_type': 'start', 'timestamp': 6, 'base_rate_per_minute': 1}, {'order_id': 'B', 'event_type': 'complete', 'timestamp': 10}], [(0, 3), (2, 6)])

Expected Output: 28

Explanation: Peak ranges merge to [0,6). Order A overlaps 5 peak minutes, so pay is 2 * (7 + 5) = 24. Order B is [6,10), which does not overlap [0,6) under half-open interval rules, so it pays 4. Total = 28.

Input: ([{'order_id': 'A', 'event_type': 'start', 'timestamp': 5, 'base_rate_per_minute': 2}, {'order_id': 'A', 'event_type': 'complete', 'timestamp': 10}, {'order_id': 'B', 'event_type': 'start', 'timestamp': 4, 'base_rate_per_minute': 3}, {'order_id': 'B', 'event_type': 'complete', 'timestamp': 3}, {'order_id': 'C', 'event_type': 'start', 'timestamp': 0, 'base_rate_per_minute': 1}], [(6, 8), (9, 9), (12, 11)])

Expected Output: 14

Explanation: Only A is a valid order. Only peak period (6,8) is valid. Order A has duration 5 and peak overlap 2, so pay is 2 * (5 + 2) = 14.

Input: ([], [(0, 5)])

Expected Output: 0

Explanation: No events means no pay.

Input: ([{'order_id': 'Z', 'event_type': 'start', 'timestamp': 2, 'base_rate_per_minute': 5}, {'order_id': 'Z', 'event_type': 'complete', 'timestamp': 6}], [])

Expected Output: 20

Explanation: With no peak periods, the calculation falls back to normal base pay: (6 - 2) * 5 = 20.

Hints

  1. First merge the peak periods so you work with disjoint sorted ranges.
  2. After merging, compute how many minutes of each valid order fall inside peak time, then add base pay plus one extra base-rate copy for the overlapped minutes.
Last updated: May 1, 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)