Event Stream And Interval Pay Computation
Asked of: Software Engineer
Last updated
What's being tested
These problems test event-stream interval aggregation: converting unordered start/stop events into active time segments, then applying rates, overlaps, and conditional multipliers correctly. You must demonstrate careful input validation, deterministic handling of malformed or duplicate events, exact monetary arithmetic, and clear O(n log n) algorithmic reasoning.
Patterns & templates
-
Sweep line — convert starts to
+1and ends to-1, sort timestamps, then charge each interval using the active count before applying the delta. -
Interval aggregation — for consecutive timestamps
t[i-1],t[i], contribution is(t[i] - t[i-1]) × active_orders × rate; skip zero-length segments. -
Event pairing — maintain
open_order_id → start_time; reject unmatched ends, duplicate starts, negative durations, and invalid event types explicitly. -
Conditional rates — split intervals at every peak-window boundary, then apply the correct multiplier per segment rather than classifying only by start time.
-
Money arithmetic — represent cents as integers, such as
30cents per minute; round only once at the final boundary using the stated rule. -
Daily boundaries — intersect each delivery interval with
[day_start, day_end); use half-open intervals to avoid double-counting midnight or adjacent segments. -
Complexity target — sorting dominates at
O(n log n)time andO(n)space; a hash map plus sorted events is appropriate for millions of records.
Common pitfalls
Pitfall: Charging each order independently can miscompute concurrent-rate rules; aggregate active count across sorted timestamps instead.
Pitfall: Using floating-point dollars introduces rounding errors; parse timestamps consistently and compute in integer cents or exact decimals.
Pitfall: Silently “fixing” malformed or duplicate events creates non-deterministic pay; define whether to reject, ignore, or deduplicate and explain why.
Practice these
The practice cards below cover the canonical variants—solve all of them and time yourself.
Practice questions
- Compute Delivery Pay from an Event Stream and Peak WindowsDoorDash · Software Engineer · Onsite · medium
- Build a Delivery Payout Calculation APIDoorDash · Software Engineer · Technical Screen · medium
- Compute Driver Pay with Double-Pay WindowsDoorDash · Software Engineer · Technical Screen · medium
- Calculate Daily Driver PayDoorDash · Software Engineer · Technical Screen · hard
- Design Real-Time Driver Pay AggregationDoorDash · Software Engineer · Technical Screen · hard
- Compute dasher pay from order event logsDoorDash · Software Engineer · Online Assessment · medium
- Calculate Courier EarningsDoorDash · Software Engineer · Technical Screen · medium
- Compute dasher payout from API dataDoorDash · Software Engineer · Onsite · medium
- Implement dasher active-time calculatorDoorDash · Software Engineer · Technical Screen · medium
- Compute dasher pay from deliveriesDoorDash · Software Engineer · Onsite · medium
- Compute courier pay with peak-hour rulesDoorDash · Software Engineer · Technical Screen · medium
Related concepts
- Monetary Pay Computation And Event-Time AggregationData Manipulation (SQL/Python)
- Time Interval Overlap And Sweep-Line AlgorithmsCoding & Algorithms
- Temporal Event Processing and Interval LogicCoding & Algorithms
- Stateful Stream Processing And Time SchedulingCoding & Algorithms
- Delivery Driver Payment And Cost SystemsSystem Design
- Temporal Event Processing And Interval AlgorithmsCoding & Algorithms