Intervals

There are two types of intervals

  • Overlapping intervals

  • Non Overlapping intervals

They can be used to solve variety of problems:

  1. Merge Overlapping Intervals: Given a list of intervals, merge overlapping intervals into a consolidated list of intervals. This can be used in scenarios like scheduling, time management, or resource allocation.

  2. Non-overlapping Intervals: Given a list of intervals, find the maximum number of non-overlapping intervals that can be selected. This can be used in scenarios like task scheduling, activity selection, or maximizing resource utilization.

  3. Interval Intersection: Given two lists of intervals, find the intersection between them. This can be used in scenarios like finding common availability slots, overlapping events, or time-based conflicts.

  4. Interval Union: Given a list of intervals, find the union of all overlapping intervals. This can be used in scenarios like visualizing time ranges, determining the overall coverage of events, or determining the total duration of overlapping activities.

  5. Interval Difference: Given two lists of intervals, find the difference between them (intervals present in one list but not in the other). This can be used in scenarios like finding available time slots, identifying gaps in schedules, or filtering out unwanted intervals.

Practice Problems

  1. Merge Overlapping Intervals:

  2. Interval Union:

  3. Interval Difference:

Last updated

Was this helpful?