← 返回 doordash 的题目列表Implement Dasher Pay Calculation (Minute-based, Overlapping Orders)
类型:online_judge
Problem: Implement Dasher Pay Calculation (Minute-based, Overlapping Orders)
You need to implement a module/class to calculate a delivery dasher’s pay. The system contains multiple orders; for each order, the dasher earns money per minute from accept to deliver.
Pay rules
Each order has a per-minute rate.
For a given dasher and any minute:
If the dasher is simultaneously active on k orders during that minute (i.e., all k orders are “in progress” for that minute), then the income for that minute is:
income_this_minute = k * rate
Assume all orders for the same dasher share the same rate (if you think per-order rates are needed, state and support it).
Time definition
Time is represented in integer minutes.
Each order provides accept_minute and deliver_minute.
The active interval is half-open: [accept_minute, deliver_minute).
Example: accept=10, deliver=12 covers minutes 10 and 11 (2 minutes).
Input / API
Design an OOP-style interface and internal data structures that support:
Adding an order with dasher_id, accept_minute, deliver_minute (and optional rate).
Querying total earnings for a given dasher_id (or for all dashers).
Output
Return the total pay for the requested dasher (integer or float depending on rate).
Constraints (to be clarified with interviewer)
Number of orders N up to 1e5.
Time range in minutes up to 1e9.
You must explain time/space complexity.
Example
Let rate = 2:
Order1: dasher=A, [0, 3)
Order2: dasher=A, [1, 2)
Per minute:
minute 0: 1 order -> 1*2=2
minute 1: 2 orders -> 2*2=4
minute 2: 1 order -> 1*2=2
Total pay = 8
Requirements
Implement the core logic.
Provide at least 5 test cases covering edge scenarios (no overlap, full overlap, partial overlaps, 1-minute orders, large time gaps, etc.).
Example
Input
A
2
order 0 3 rate=2
order 1 2 rate=2
query A
Output
8