solving sequence of intervals problem