Peak Concurrent Streams and Time Spent Over a Rate Limit

Last updated: November 29, 2026

Quick Overview

Given API request intervals as half-open (start_ms, end_ms) pairs and a concurrency limit, return the peak number of simultaneously open streams and the total milliseconds during which concurrency exceeded the limit.

OpenAI
Coding & Algorithms
Software Engineer
OpenAI
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given API request intervals as half-open (start_ms, end_ms) pairs and a concurrency limit, return the peak number of simultaneously open streams and the total milliseconds during which concurrency exceeded the limit.

The OpenAI API enforces concurrency and rate limits per organization, and capacity planning depends on how long traffic sat above a threshold, not just the peak. This sweep-line question checks tie handling at shared endpoints, integrating a duration over a piecewise-constant function, and clear interval semantics.

What the Interviewer Expects
  • Turn intervals into +1 and -1 events and sort them
  • Process ends before starts at the same timestamp for half-open intervals
  • Accumulate time above the limit between consecutive events
  • Ignore or reject zero-length intervals deliberately
  • Explain O(n log n) time
Key Topics to Cover
sweep line
intervals
event sorting
concurrency
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Timestamps arrive as a stream already sorted by start: can you avoid sorting everything?
  • Report the busiest one-second window instead of instantaneous peak.
  • Each request has a weight (tokens per second): compute peak load in tokens per second.
  • How would you compute this per organization across billions of log lines?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Intervals are half-open: a request ending at 10 and another starting at 10 do not overlap.
  • Output: (peak, over_ms) where over_ms is total time with active count strictly greater than limit. ...
High-Level Design

Concurrency is a step function that only changes at interval endpoints. Emit (start, +1) and (end, -1), then sort. Sorting tuples places -1 before +1 at equal times, which implements half-open...


Submit Your Answer
Markdown supported