LC: 1272. Remove Interval - spiralgo/algorithms GitHub Wiki

1272. Remove Interval

The Essence:

For interval removal there are 3 cases:

  1. The entire interval is outside the removal range, after or before it.
  2. The entire interval is in the removal range.
  3. 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.