Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Peak Capacity Intervals

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

Your question is Peak Capacity Intervals. 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

Faire's marketplace operations team represents each active capacity reservation as a time interval. Given all reservations, return the time intervals during which the number of concurrent reservations is at its maximum.

Treat intervals as half-open, [start, end): a reservation is active at start but not at end. If multiple peak intervals are directly adjacent, merge them into one interval.

Formal Specification

Implement peak_capacity_intervals(intervals), where intervals is a list of two-element integer lists [start, end]. Return a list of two-element lists representing the maximal disjoint intervals [start, end] during which the concurrent reservation count equals the global maximum. Return [] when intervals is empty.

Constraints

  • 0 <= len(intervals) <= 10^5
  • Each interval contains exactly two integers
  • start < end for every interval
  • -10^9 <= start < end <= 10^9
  • Intervals may be unsorted

Function Signature

def peak_capacity_intervals(intervals):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output