Member-only story
Grokking the Coding Interview
Coding Interview Pattern: Merge Interval
How learning coding patterns makes interview preparation easy and efficient.
Being a pro at coding patterns makes life easier because we can quickly spot similarities between new problems and ones we’ve tackled before. This makes finding solutions a breeze.
One super important coding pattern to know is the Merge Interval. On is one of the most frequently occurring patterns in Coding Interviews. Let’s dive in and learn when and how to use it.
Merge Interval 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 (‘a’ and ‘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 intervals related problems.
Let’s jump onto a coding problem to understand the Merge Interval pattern.