Proof that two intervals are enough: it makes no sense to choose an interval that is correctly contained in another interval. Without loss of generality, let the intervals be [a1, b1], ..., [an, bn] such that a1 <... <ap. If no interval properly contains another interval, then b1 <... <billion. For i <j <k, he believes that ([ai, bi] intersect [aj, bj] intersect [ak, bk]) = ([ai, bi] intersect [ak, bk]) and are the same for the union, so there is no reason to choose more than two intervals.
O (n log n) -time algorithm:, the problem is to find the intervals [a, b] and [c, d] of maximization (d - a) * (b - c), since this product is negative if intervals do not intersect. Our algorithm is to pre-process O (n log n), which allows us to find the best helper for each interval in O (log n) time.
Let the job of finding the best helper for [a, b]. Take some algebra: (d - a) * (b - c) = d * b - d * c - a * b + a * c. Since a, b are fixed, we can drop the term -a * b and maximize the scalar product <(a, b, 1), (d, c, -d * c)> over all intervals [c, d], since the set of vectors (d, c, -d * c) is fixed, this essentially simulates the collision of a stationary polyhedron and a moving plane perpendicular to (a, b, 1). Thanks to Edelsbrunner and Maurer ( Finding Extreme Points in Three Dimensions and Solving the Mail Branch Problem in the Plane , 1984), there is an algorithm that preprocesses in time O (n log n) and solves queries of this type for different a and b in O (log n ) time.
One of the sour details is that we must choose at least two intervals, but the best βsolutionβ may be the longest interval with ourselves. I'm sure this is messy, but it's possible to expand Edelsbrunner - Maurer to find the second most extreme point in the same run time.