Leetcode problem 57.
Sometimes, it is probably easier to think in terms of progression rather than cases.
In this case, we separate the while loops into three different ‘progressions’:
- Non-overlap at the start
- Overlap parts, we can ensure that this will be a first half overlap rather than the second half overlap
- This means that the
newIntervalalways comes first before the incominginterval
- This means that the
- Non-overlap at the end