Courier pay from order events
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in SpaceXAI's technical phone screen, last asked Mar 2026. It tests event processing, intervals and simulation.
A delivery courier earns $0.30 per minute for each order they have active. An order is active from the moment it is accepted until it is fulfilled, so overlapping orders multiply the rate. Given the courier's events, compute their total pay.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
total_pay(events: list[tuple[int, str, str]]) -> float— each event is(time_in_minutes, order_id, action)with action"ACCEPT"or"FULFILL". Returns dollars rounded to two decimals.
Events may be unsorted: process them by time, and at equal times apply every ACCEPT before any FULFILL. Over each interval between consecutive event times, the number of active orders is the count after applying the events at the interval's start.
Example
total_pay([(405, "B", "FULFILL"), (375, "A", "ACCEPT"),
(378, "B", "ACCEPT"), (396, "A", "FULFILL")]) -> 14.4
# 375-378: 1 order x 3 min; 378-396: 2 x 18; 396-405: 1 x 9
# 48 order-minutes x 0.30 = 14.40
total_pay([]) -> 0.0
Constraints
- Up to
2 * 10^5events; times up to10^9. - Treat the events as coming from another service; agree on how much to validate.
Clarifying questions
- Are events sorted? How are ties ordered?
- Is the input guaranteed valid (accept before fulfill, no duplicates)?
- Is pay per started minute or exact minutes?
- How should money be represented and rounded?
What a strong answer covers
- Sort by
(time, ACCEPT first), sweep with a running count of active orders, and addcount × (next_time - time)order-minutes. - Integer order-minutes accumulated, then converted to money once at the end (integer cents), avoiding float drift.
- Validation choices for upstream data: fulfill without accept, double accept, orders never fulfilled; reject, skip or report.
- O(n log n) time; tests for same-time accept and fulfill, and for no events.
Follow-ups
- The rate depends on the number of active orders (for example a bonus from the third order).
- Pay per calendar day when shifts cross midnight.
- Events arrive as a stream; report pay so far at any time.
Where it's asked
- SpaceXAI · Technical phone screen · Last asked Mar 202645 min · Live applied coding on a shared platform such as CoderPad · No AI
What it tests
event processing · intervals · simulation
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
