Katkat

Compute dasher pay from order events

xAISoftware Engineer · Technical Screen

Last 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:

  • time is an integer timestamp in minutes (e.g., minutes since midnight).
  • orderId is a string identifier.
  • action is one of: ACCEPT, FULFILL.

Output

Return the total pay as a double, rounded to two decimals.

Important details / assumptions

  • events may be unsorted; you must process them in increasing time.
  • If multiple events have the same time, process all ACCEPT actions before FULFILL actions 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 at t_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