Блог пользователя rumike

Автор rumike, история, 5 часов назад, По-английски

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) ?

  • Проголосовать: нравится
  • -9
  • Проголосовать: не нравится

»
4 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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)$$$.

  • »
    »
    21 минуту назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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).

»
4 часа назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
11 минут назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by rumike (previous revision, new revision, compare).