← 返回 doordash 的题目列表Calculate Dasher Pay from Delivered Orders
类型:online_judge
Problem: Calculate Dasher Pay from Order Time Ranges (with Mock Service Call)
You are given an external service that, for a given dasher_id, returns a list of delivered orders with their delivery time ranges:
start_time: when the delivery work for an order started
end_time: when it ended
You are also given a per-minute pay rate rate_per_minute. Compute the total pay for the dasher.
Requirements
Implement a function/module that retrieves the order ranges via a mock API/service call (no real networking needed; just simulate the service response in code).
Compute and return the total pay based on the returned time ranges.
Base Pay Rule
Duration of an order is end_time - start_time (in minutes).
Total pay = (sum of all order durations) × rate_per_minute.
Follow-up (Overlapping Ranges)
If a dasher can accept multiple orders concurrently and the time ranges overlap, implement a version that computes pay based on the actual working time by taking the union of all time ranges (i.e., do not double-count overlapping minutes).
I/O Contract (suggested)
Input: dasher_id (string/int), rate_per_minute (int/float)
Service output: list of ranges [(start, end), ...] where times are comparable (e.g., integer minutes from 0 or timestamps)
Output: total pay (numeric)
Constraints
Number of orders n: 1 ≤ n ≤ 2e5
Times are integer minutes (assume basic validation by the service)
Example Test Cases (minute indices)
Non-overlapping: [(0,10),(20,30)], rate=2 → pay=40
Overlapping (union): [(0,10),(5,12)], rate=3 → union=12 mins → pay=36
Containment: [(0,10),(2,5)], rate=1 → union=10 → pay=10
Touching: [(0,10),(10,15)], rate=2 → union=15 → pay=30
Mixed: [(1,4),(2,6),(8,10),(9,12)], rate=5 → union=9 → pay=45
Example
Input
d2
2
Output
40