Imagine we have a 1 dimensional floor where a position on the floor is given by a x-coordinate.
In this floor there can be a hole represented by an interval (e.g. 2 to 8 represents that the floor has a hole in it from position 2 to position 8.
Furthermore, the holes can be covered. This is done via another interval where we remove the overlapping part of this interval and the hole interval from the hole interval. (e.g. 6 to 10 represents that this part of the floor gets covered. This means that since we had a hole at 2 to 8, and we covered 6 to 10, we now only have a hole from 2 to 6, but not from 6 to 8 because this part of the hole interval was covered)
Because I am keeping track of all the holes through a list and I have no interest in storing a list of covers, all I want to do is update my list of holes when given a cover.
Lets say we have the hole interval 2 to 8 and cover interval 6 to 10:
hole_start = 2
hole_end = 8
cover_start = 6
cover_end = 10
How do I get the new hole start and end?
new_hole_start = 2
new_hole_end = 6
Note that we need to account for any scenario like:
- no overlap (e.g. Hole = (2, 8) and Cover = (0, 1)
- complete overlap (e.g. Hole (2, 8) and Cover (0, 10)
- partial overlap from left (e.g. Hole (2, 8) and Cover (0, 4)
- partial overlap from right (e.g. Hole (2, 8) and Cover (6, 8)