11
We are given a continuous stream of integer ranges like [1,3], [5,10], [2,6], ... when each new range comes, we need to check with existing ranges and see if it overlaps with any existing range, and if any overlap is found, all the overlapping ranges are removed and the merged range is inserted instead. We need an efficient algorithm for this. Note that the range comes one at a time which forms a stream...
Was asked this question during an interview. Ideas?
The intent is to merge overlapping ranges into one. for example, if we have 3 ranges coming in the following order: [1,3], [2,6], [5,10]. Then we first merge the first two into [1,6], then merge with the 3rd and it becomes [1,10].