Dasher Active Pay
MediumIntervals · DoorDash
A dasher's shift is described by a log of order events. Each event is [minute, order_id, action], where action is either "accept" or "deliver". Every order appears exactly twice: once when it is accepted and once, at the same minute or later, when it is delivered. The log is sorted by minute.
Pay accrues per minute and per active order. An order is active from its accept minute up to (but not including) its deliver minute, so an order accepted at minute 3 and delivered at minute 7 is active for 4 minutes. If k orders are active during a minute, the dasher earns k * base_cents_per_minute cents for that minute.
peak_windows lists half-open periods [start, end) during which the per-minute rate is doubled. Peak windows do not overlap each other, but they may be given in any order. Minutes when no order is active earn nothing, even inside a peak window.
Return the dasher's total pay in cents.
Example 1
- Input:
- events = [[0, "A", "accept"], [10, "B", "accept"], [20, "A", "deliver"], [30, "B", "deliver"]], base_cents_per_minute = 10, peak_windows = [[15, 25]]
- Output:
- 550
- Explanation
- From 0 to 10 only A is active (100 cents). From 10 to 15 both are active (100). From 15 to 20 both are active at the doubled peak rate (200), from 20 to 25 only B at the peak rate (100), and from 25 to 30 only B at base rate (50), for 550.
Example 2
- Input:
- events = [[5, "X", "accept"], [12, "X", "deliver"], [12, "Y", "accept"], [15, "Y", "deliver"]], base_cents_per_minute = 30, peak_windows = []
- Output:
- 300
- Explanation
- X is active for 7 minutes and Y for 3. X is delivered at minute 12 exactly when Y is accepted, so they never overlap, and with no peak windows the pay is 10 minutes at 30 cents.
Example 3
- Input:
- events = [[100, "P", "accept"], [100, "Q", "accept"], [110, "Q", "deliver"], [130, "P", "deliver"]], base_cents_per_minute = 5, peak_windows = [[120, 180], [90, 105]]
- Output:
- 300
- Explanation
- Peak windows can come in any order. From 100 to 105 both orders are active inside the
[90, 105)peak (2 x 5 min x 10 cents = 100). From 105 to 110 both are active at base rate (50), from 110 to 120 only P at base (50), and from 120 to 130 only P inside the[120, 180)peak (100), for 300.
Constraints
0 <= events.length <= 2 * 10^50 <= minute <= 10^9, andeventsis sorted byminute- Every
order_idhas exactly one"accept"and one later-or-equal"deliver"event 1 <= base_cents_per_minute <= 10^40 <= peak_windows.length <= 10^5, each withstart < end, and windows do not overlap