← 返回 doordash 的题目列表Compute Dasher Daily Payment from Order Events (with Peak Hour Rate Doubling)
类型:online_judge
Problem: Compute Dasher Daily Payment from Work-Interval Events (with Peak-Hour Doubling)
You are given an ordered sequence of events for a dasher within a day (input as a JSON array, each element is an event). Compute the dasher's total pay for that day.
Events as billable intervals
Each event contains at least:
start: start timestamp (integer, seconds)
end: end timestamp (integer, seconds), with end > start
payRate: base rate for this interval (int/float, pay per second)
Each event represents a billable work interval [start, end).
Note: In the original interview the input was an open-ended JSON event schema. Here we normalize it into billable intervals with a base rate.
Peak-hour doubling (follow-up 2)
You are also given one or more peak-hour intervals peaks. During peak time, the pay rate is doubled. If a billable interval partially overlaps a peak interval, you must split at peak boundaries and charge accordingly.
Peak intervals use [pStart, pEnd).
For any second that lies in any peak interval, the effective rate is 2 * payRate, otherwise it is payRate.
Goal
Output the total pay (may be fractional).
Input (stdin)
Line 1: JSON array events. Line 2: JSON array peaks.
Where:
events[i] = {"start": int, "end": int, "payRate": number}
peaks[j] = {"start": int, "end": int}
Output (stdout)
Print the total pay for the day.
Constraints
1 <= len(events) <= 2e5
0 <= start < end <= 86400
0 <= payRate <= 1e6
1 <= len(peaks) <= 2e5
Must be efficient; no per-second simulation.
Example
Input
[{"start":0,"end":10,"payRate":1},{"start":10,"end":20,"payRate":2}]
[{"start":5,"end":15}]
Output
35
Explanation Split intervals at peak boundaries and apply a 2x multiplier inside peak ranges.
Example
Input
[{"start":0,"end":10,"payRate":1}]
[{"start":0,"end":10}]
Output
20