PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches

Quick Overview

This question evaluates a candidate's ability to process time-based event streams, manage overlapping active intervals, and compute aggregate payouts under concurrency constraints.

  • nan
  • xAI
  • Coding & Algorithms
  • Software Engineer

Compute dasher pay from order events

Company: xAI

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: nan

Interview Round: Technical Screen

## 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 **ACCEPT**ed until it is **FULFILL**ed. - 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

Quick Answer: This question evaluates a candidate's ability to process time-based event streams, manage overlapping active intervals, and compute aggregate payouts under concurrency constraints.

You are given a list of delivery events for a Dasher. Each event is a tuple (time, orderId, action), where action is either "ACCEPT" or "FULFILL". An order is active from the moment it is accepted until it is fulfilled. The Dasher earns $0.30 per minute for each active order, so overlapping orders increase pay multiplicatively by concurrency. The input list may be unsorted. Process events in increasing time order, and if multiple events happen at the same time, process all "ACCEPT" actions before all "FULFILL" actions. For each interval [t_i, t_{i+1}), the active order count is the count after applying all events at t_i. Return the total pay as a float rounded to two decimal places.

Constraints

  • 0 <= len(events) <= 200000
  • 0 <= time <= 10^9
  • action is either "ACCEPT" or "FULFILL"
  • The input is valid: every fulfilled order has a matching earlier or same-time accept when same-time actions are ordered as specified

Examples

Input: ([(405, 'B', 'FULFILL'), (375, 'A', 'ACCEPT'), (378, 'B', 'ACCEPT'), (396, 'A', 'FULFILL')],)

Expected Output: 14.4

Explanation: After sorting: 375-378 has 1 active order, 378-396 has 2, and 396-405 has 1. Total active-order minutes = 3 + 36 + 9 = 48, so pay = 48 * 0.30 = 14.4.

Input: ([],)

Expected Output: 0.0

Explanation: No events means no active orders and therefore no pay.

Input: ([(10, 'A', 'ACCEPT'), (10, 'A', 'FULFILL'), (15, 'B', 'ACCEPT'), (20, 'B', 'FULFILL')],)

Expected Output: 1.5

Explanation: Order A is accepted and fulfilled at the same timestamp, so it contributes no paid interval. Order B is active from 15 to 20 for 5 minutes, so pay = 5 * 0.30 = 1.5.

Input: ([(15, 'C', 'FULFILL'), (5, 'A', 'ACCEPT'), (12, 'A', 'FULFILL'), (7, 'B', 'ACCEPT'), (10, 'B', 'FULFILL'), (8, 'C', 'ACCEPT')],)

Expected Output: 5.1

Explanation: Sorted intervals: 5-7 has 1 active, 7-8 has 2, 8-10 has 3, 10-12 has 2, 12-15 has 1. Total active-order minutes = 2 + 2 + 6 + 4 + 3 = 17, so pay = 17 * 0.30 = 5.1.

Input: ([(1, 'A', 'ACCEPT'), (4, 'A', 'FULFILL'), (4, 'B', 'ACCEPT'), (6, 'B', 'FULFILL')],)

Expected Output: 1.5

Explanation: From 1 to 4, A is active for 3 minutes. At time 4, B is accepted and A is fulfilled, leaving 1 active order from 4 to 6 for 2 more minutes. Total active-order minutes = 5, so pay = 1.5.

Hints

  1. Sort the events by timestamp, and for equal timestamps make sure ACCEPT comes before FULFILL.
  2. Instead of adding floating-point pay each time, accumulate total active-order minutes first, then convert to dollars at the end.
Last updated: May 16, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Flatten and unflatten nested Python structures - xAI (nan)
  • Compute total active time per Twitter Space - xAI (medium)
  • Design a Recoverable Iterator - xAI (medium)
  • Implement Distributed Matrix Multiplication - xAI (hard)
  • Maximize distinct values after unique ± offsets - xAI (hard)