compute the union of intervals