Efficient technique to deal with overlapping intervals.
Mechanism
- Given two intervals (
a
andb
), there will be six different ways the two intervals can relate to each othera
andb
don’t overlap,b
ends aftera
a
andb
overlap,b
ends aftera
a
completely overlapsb
a
andb
overlap,a
ends afterb
b
completely overlapsa
a
andb
don’t overlap,a
ends afterb
When to use
- If you hear the term “overlapping intervals”.
- Merge intervals if they overlap
- If you’re asked to produce a list with only mutually exclusive intervals