PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches

Quick Overview

This English summary evaluates the candidate's proficiency in algorithm design and complexity analysis within the Coding & Algorithms domain, specifically for aggregating interval data and computing concurrent counts.

  • Medium
  • Rippling
  • Coding & Algorithms
  • Software Engineer

Compute maximum simultaneous drivers

Company: Rippling

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Given N driver online intervals [start_time, end_time) during a day, compute the maximum number of drivers simultaneously online at any moment. Handle large N, overlapping intervals, and identical timestamps. Describe and implement an efficient algorithm, analyze time and space complexity, and discuss how to support streaming updates where intervals arrive incrementally and may be corrected.

Quick Answer: This English summary evaluates the candidate's proficiency in algorithm design and complexity analysis within the Coding & Algorithms domain, specifically for aggregating interval data and computing concurrent counts.

Given N half-open driver online intervals [start_time, end_time) during a day, return the maximum number of drivers who are online at the same moment. Intervals may overlap heavily, multiple intervals may share identical timestamps, and N can be large, so an O(N^2) approach is too slow. Important details: - A driver is online at start_time. - A driver is not online at end_time. - Zero-length intervals [t, t) contribute nothing. For the coding task, implement the efficient batch algorithm. As a follow-up discussion, explain how you would support streaming interval inserts, deletes, or corrections as data arrives incrementally.

Constraints

  • 0 <= N <= 200000
  • -10^9 <= start_time <= end_time <= 10^9
  • Intervals are half-open: [start_time, end_time)
  • Many intervals may share the same start or end timestamp

Examples

Input: ([],)

Expected Output: 0

Explanation: There are no intervals, so no drivers are ever online.

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

Expected Output: 1

Explanation: A single non-empty interval means exactly one driver is online from time 5 up to, but not including, 10.

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

Expected Output: 1

Explanation: Because intervals are half-open, each interval ends exactly when the next begins, so they never overlap.

Input: ([[1, 4], [1, 4], [1, 4], [2, 2]],)

Expected Output: 3

Explanation: The zero-length interval [2, 2) contributes nothing. The other three identical intervals overlap completely, so the maximum is 3.

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

Expected Output: 3

Explanation: The zero-length interval [0, 0) contributes nothing. The maximum number of simultaneous drivers is 3, achieved on [2, 3) and again on [3, 4).

Input: ([[1, 5], [2, 5], [5, 7], [5, 8], [5, 5]],)

Expected Output: 2

Explanation: At time 5, the first two intervals end and the next two begin. Since end_time is excluded, the count remains 2, and [5, 5) contributes nothing.

Solution

def solution(intervals):
    from collections import defaultdict

    delta = defaultdict(int)

    for start, end in intervals:
        if start >= end:
            continue
        delta[start] += 1
        delta[end] -= 1

    current = 0
    best = 0

    for time in sorted(delta):
        current += delta[time]
        if current > best:
            best = current

    return best

Time complexity: O(N log N). Space complexity: O(N).

Hints

  1. Convert each interval into two events: +1 when a driver comes online and -1 when a driver goes offline.
  2. Because intervals are [start, end), drivers ending at time t should not be counted at t. Aggregating all changes by timestamp and sweeping in sorted order handles identical timestamps correctly.
Last updated: May 21, 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

  • Implement logger and card ranking - Rippling (medium)
  • Design a Driver Payroll System - Rippling (medium)
  • Compare Complete or Partial Hands - Rippling (medium)
  • Implement Food Delivery Billing - Rippling (medium)
  • Implement a balance tracker and interval merger - Rippling (medium)