Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find Missing Subranges

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

Your question is Find Missing Subranges. 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

Collective Health processes covered service-day ranges for a member. Given inclusive integer intervals that are already covered, return all inclusive ranges not covered within an absolute minimum and maximum value.

Intervals may be unsorted, overlapping, adjacent, or fully contained within another interval. The output must be sorted by range start, non-overlapping, and must not include values outside [minimum, maximum]. Each output range should be represented as a two-element list [start, end].

Formal Specification

Implement missing_ranges(ranges, minimum, maximum), where ranges is a list of inclusive integer intervals and minimum <= maximum. Return a list of inclusive integer intervals representing the complement of the union of ranges within [minimum, maximum].

All input intervals are valid and lie within the absolute bounds.

Constraints

  • 0 <= len(ranges) <= 10^5
  • minimum <= maximum
  • -10^9 <= minimum <= maximum <= 10^9
  • Each interval is an inclusive pair [start, end]
  • All intervals lie within [minimum, maximum]

Function Signature

def missing_ranges(ranges, minimum, maximum):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output