LC: 1272. Remove Interval - spiralgo/algorithms GitHub Wiki
The Essence:
For interval removal there are 3 cases:
- The entire interval is outside the removal range, after or before it.
- The entire interval is in the removal range.
- Some parts of the interval are before and/or some parts of the interval are after the removal range.
Details:
The intervals in the first case get directly added. The second case intervals are dismissed. For the third case, it can be noticed that a new interval arises in the are beginning from the interval start up to the removal range start. This new interval can be added. the same applies for the situation where a part of the interval left at the end creates a new interval there.