Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Max Overlapping Events

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Max Overlapping Events. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Cohere monitors intervals during which requests to products such as the Cohere API are being processed. Given request intervals and a time window, return the maximum number of requests active simultaneously within that window.

Treat every interval as half-open: [start, end). An event is active at time t when start <= t < end. Events ending at time t do not overlap events starting at time t.

Formal Specification

Implement max_overlapping_events(events, window_start, window_end), where events is a list of two-element lists [start, end], and all timestamps are integers. The function must consider only the portions of events that intersect [window_start, window_end). Return an integer representing the greatest number of simultaneously active events in that window. Return 0 if no event intersects the window.

Constraints

  • 0 <= len(events) <= 10^5
  • 0 <= window_start < window_end <= 10^9
  • Each event satisfies 0 <= start < end <= 10^9
  • Timestamps are integers
  • Intervals are half-open: [start, end)

Function Signature

def max_overlapping_events(events, window_start, window_end):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output