Skip to main content

Introduction to Merge Intervals

This pattern describes an efficient technique to deal with overlapping intervals. In a lot of problems involving intervals, we either need to find overlapping intervals or merge intervals if they overlap.

Given two intervals (aand b), there will be six different ways the two intervals can relate to each other:

Understanding the above six cases will help us in solving all interval-related problems. Let’s jump onto our first problem to understand the Merge Interval pattern.