PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question set evaluates algorithmic problem-solving in scheduling and resource allocation, assessing understanding of batching under capacity and time-window constraints and interval-overlap reasoning for concurrent resource assignment within the Coding & Algorithms domain, and emphasizes practical application of algorithmic techniques and complexity analysis rather than purely theoretical proof. These problems are commonly asked to measure a candidate's ability to model time-based constraints, reason about resource utilization and scalability, and design efficient approaches for real-world scheduling and allocation scenarios.

  • medium
  • DoorDash
  • Coding & Algorithms
  • Machine Learning Engineer

Minimize batches and allocate riders by time

Company: DoorDash

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Coding prompts (same interview round) ### 1) Minimum number of batches for time points You are given a list of event time points (integers), e.g. `[1, 3, 5, ...]`. You need to group all events into **batches** under these constraints: - Each batch can contain **at most `B`** events (capacity). - Let `t0` be the **earliest time** in a batch. Then **every** event time `t` in that batch must satisfy: - `t - t0 <= W` (i.e., all events lie within a window of size `W` starting at the earliest event in the batch). **Goal:** return the **minimum number of batches** needed to include all events. **Input:** - `times`: array of integers (not guaranteed sorted) - integers `B` (capacity), `W` (window) **Output:** - minimum number of batches **Notes:** - You may assume `B >= 1`, `W >= 0`. - The implementation should be runnable and include self-chosen test cases. --- ### 2) Follow-up: minimum number of riders (Meeting Rooms II variant) In a delivery setting, each order occupies a rider for an interval of time `[start, end)` (or `[start, end]`—clarify your convention). Given a list of order time intervals, compute the **minimum number of riders** needed so that no rider is assigned overlapping orders. **Input:** list of intervals `(start, end)` **Output:** minimum number of riders required (Expect a sweep-line / min-heap style solution.)

Quick Answer: This question set evaluates algorithmic problem-solving in scheduling and resource allocation, assessing understanding of batching under capacity and time-window constraints and interval-overlap reasoning for concurrent resource assignment within the Coding & Algorithms domain, and emphasizes practical application of algorithmic techniques and complexity analysis rather than purely theoretical proof. These problems are commonly asked to measure a candidate's ability to model time-based constraints, reason about resource utilization and scalability, and design efficient approaches for real-world scheduling and allocation scenarios.

Part 1: Minimum Batches for Time Points

You are given a list of integer event times. Group all events into batches such that each batch contains at most B events, and if t0 is the earliest time in a batch, then every event t in that batch must satisfy t - t0 <= W. Return the minimum number of batches needed to include all events. The input list is not guaranteed to be sorted.

Constraints

  • 0 <= len(times) <= 200000
  • -10^9 <= times[i] <= 10^9
  • 1 <= B <= 200000
  • 0 <= W <= 10^9

Examples

Input: ([7, 1, 3, 2, 9], 3, 2)

Expected Output: 2

Explanation: After sorting: [1, 2, 3, 7, 9]. One optimal grouping is [1, 2, 3] and [7, 9].

Input: ([], 4, 10)

Expected Output: 0

Explanation: There are no events, so no batches are needed.

Input: ([5, 5, 5, 6, 6], 2, 0)

Expected Output: 3

Explanation: With W = 0, only equal times can share a batch. The 5s need two batches because B = 2, and the 6s fit in one batch.

Input: ([-2, -1, -1, 0, 4], 3, 1)

Expected Output: 3

Explanation: After sorting: [-2, -1, -1, 0, 4]. One optimal grouping is [-2, -1, -1], [0], [4].

Input: ([4, 1, 7, 2, 3, 8], 2, 10)

Expected Output: 3

Explanation: The time window is large enough to allow many combinations, but each batch can hold at most 2 events, so 6 events require at least 3 batches.

Hints

  1. Sort the time points first. In an optimal solution, you can process events from earliest to latest.
  2. When a batch starts at the earliest remaining time, it is safe to greedily include as many following events as possible until the batch hits capacity or the window limit.

Part 2: Minimum Riders for Order Intervals

Each delivery order occupies one rider during a half-open time interval [start, end), meaning an order ending at time t does not overlap with another order starting at time t. Given a list of order intervals, return the minimum number of riders needed so that no rider is assigned overlapping orders.

Constraints

  • 0 <= len(intervals) <= 200000
  • -10^9 <= start < end <= 10^9
  • Intervals may be given in any order

Examples

Input: ([(0, 30), (5, 10), (15, 20)],)

Expected Output:

Explanation: One rider can take [0, 30). A second rider is needed for [5, 10), and then that rider can take [15, 20).

Input: ([(1, 3), (3, 5), (5, 8)],)

Expected Output:

Explanation: Because intervals are half-open, each order starts exactly when the previous one ends, so one rider is enough.

Input: ([(4, 9), (1, 5), (2, 6), (5, 7)],)

Expected Output:

Explanation: The maximum overlap occurs around time 4 to 5, where three orders are active.

Input: ([],)

Expected Output:

Explanation: No orders require no riders.

Input: ([(10, 11)],)

Expected Output:

Explanation: A single order needs one rider.

Hints

  1. Sort the intervals by start time so you process orders in chronological order.
  2. Use a min-heap of current rider end times. If the smallest end time is <= the next start time, that rider can be reused.
Last updated: Apr 25, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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

  • Validate a Shopping Cart - DoorDash (medium)
  • Calculate Driver Payments - DoorDash (medium)
  • Implement Timeout Refund Workflow - DoorDash (medium)
  • Maximize Chef Assignment Profit - DoorDash (medium)
  • Compute Courier Delivery Pay - DoorDash (easy)