Compute dasher pay from order events
xAISoftware Engineer · Technical ScreenLast updated
This question evaluates a candidate's ability to process time-based event streams, manage overlapping active intervals, and compute aggregate payouts under concurrency constraints.
Dasher naive pay (active-time with overlapping orders)
You are given a list of events describing when a delivery driver ("Dasher") accepts and fulfills different orders.
Pay rules
- Base rate: $0.30 per minute.
- An order is active from the time it is ACCEPTed until it is FULFILLed.
- Pay is multiplicative by concurrency: for each minute, the dasher earns
[ \text{pay per minute} = (#\text{active orders during that minute}) \times 0.30 ]
Input
events: a list of records (time, orderId, action) where:
timeis an integer timestamp in minutes (e.g., minutes since midnight).orderIdis a string identifier.actionis one of:ACCEPT,FULFILL.
Output
Return the total pay as a double, rounded to two decimals.
Important details / assumptions
eventsmay be unsorted; you must process them in increasingtime.- If multiple events have the same
time, process allACCEPTactions beforeFULFILLactions at that same time. - Pay accrues over each interval between consecutive event timestamps. For an interval
[t_i, t_{i+1}), the number of active orders is considered constant and equals the active set after applying all actions att_i. - You may assume the input is valid: each order is accepted before it is fulfilled.
Example
Events:
- 06:15 A ACCEPT
- 06:18 B ACCEPT
- 06:36 A FULFILL
- 06:45 B FULFILL
Pay:
- 06:15–06:18: 1 active × 3 min × 0.3 = 0.9
- 06:18–06:36: 2 active × 18 min × 0.3 = 10.8
- 06:36–06:45: 1 active × 9 min × 0.3 = 2.7
Total = 14.4
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.