Given a list of interval, find the maximum difference between two intervals. The difference between two intervals A and B is the number of element that are in A and not in B, or in B and not in A.
UDP : It mean element that are exactly only in one of A and B
Can it be found in O(n) ?
I fail to see how you could do that in $$$\mathcal{O}(n)$$$ time since, at best, you would likely need to sort your intervals so as to optimise your search/counting. So, at least $$$\mathcal{O}(n\log_2 n)$$$.
I have already resolved intervals using scanline with O(n) complexity, that's why I put O(n), but I am okay with O(nlogn).
For any pair of intervals, you can first find the amount of space that is in A and the amount of space that is in B, take the max of those, and subtract off the amount of space that is in both. The max of all pairs should be the answer.
Yes but it will not be O(n^2)?
well what if n is equal to the square of the number of intervals?
Auto comment: topic has been updated by rumike (previous revision, new revision, compare).