Let's say you manage office space, and you want to report the days that it was occupied.
You're given a list of days that workers occupied the space as a list of intervals:
[[0, 3], [2, 5], [9, 10], [4, 6]]
To make the report easy to read, write a function that merges these intervals into the smallest number of disjointed interval.
The above example input should be merged into the following intervals:
[[0, 6], [9, 10]]
Note that the numbers are inclusive. I.e. the intervals
[9, 10]should be merged to
But the intervals
[7, 9]should not be merged as they're considered disjointed.